generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help

Previous Thread :: Next Thread 
dragon829 is not online. dragon829
Joined: 12 Aug 2008
Total Posts: 741
07 Nov 2011 04:21 PM
function onTouched(hit)
--script here
--ends here
script.Parent.Touched:connect(onTouched)


but im trying to figure out HOW do i make it know who hit it and changes the walkspeed to 40 when they hit it
Report Abuse
smarthimandrew is not online. smarthimandrew
Joined: 30 Jan 2010
Total Posts: 93
07 Nov 2011 04:23 PM
Wiki.Roblox.com
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Nov 2011 04:25 PM
function onTouch(hit)
hit.Parent:FindFirstChild("Humanoid")
hit.Parent.Humanoid.WalkSpeed = 40
end
script.Parent.Touched:connect(hit)

Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:27 PM
This is a simple way that checks if the part's parent (which *would* be the player's character) has a player in the `Players` service.

    script.Parent.Touched:connect(function(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            hit.Parent:FindFirstChild("Humanoid").WalkSpeed = 40
        end
    end
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:27 PM
@miz - That wouldn't work if the part's parent is not a player's character.
Report Abuse
dragon829 is not online. dragon829
Joined: 12 Aug 2008
Total Posts: 741
07 Nov 2011 04:28 PM
ill try them
Report Abuse
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
07 Nov 2011 04:28 PM
@electric

forgot close parenthesis
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:29 PM
@pompey - Ah, yes, thank you.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Nov 2011 04:34 PM
@electric

So you have to say the method?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:36 PM
@miz - ...No clue what you just asked.

But doing:

    hit.Parent:FindFirstChild("Humanoid")

Doesn't do anything. It's just a waste of a line and space. Now, you *COULD* have done something like this:

    local h = hit.Parent:FindFirstChild("Humanoid")
    if h then
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Nov 2011 04:47 PM
I just like to define Humanid by saying Findfirstchild method...It might not work because it might not be a child but still....
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:49 PM
@miz - You're not defining it! By just calling it, you're doing **ABSOLUTELY NOTHING**. You have to assign it to a variable, or use it like:

    if hit.Parent:FindFirstChild("Humanoid") then
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Nov 2011 04:50 PM
The best way is actually by using pcall. Using that, you don't need to worry about anything being nil.

script.Parent.Touched:connect(function(hit)
pcall(function() hit.Parent.Humanoid.WalkSpeed = 40 end)
end
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Nov 2011 04:51 PM
Forgot to close the parentheses.

script.Parent.Touched:connect(function(hit)
pcall(function() hit.Parent.Humanoid.WalkSpeed = 40 end)
end)
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
07 Nov 2011 04:52 PM
@electric

I say the same thing when I make a killing brick and it works!
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:55 PM
@miz - Maybe no other brick touches it? :/
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Nov 2011 04:56 PM
Ah, but if something non-human touches it, then it will break. Having the spontaneous "hit.Parent:FindFirstChild("Humanoid")" is a waste of typing.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:57 PM
@king - You just like repeated what I've been saying. :P
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Nov 2011 04:57 PM
Miz, I think you're missing the point of FindFirstChild. It returns the first child found, hence, the name; it does not check to make sure that it is there, you have to manually do that.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image