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 |
|
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 12 Aug 2008 |
| Total Posts: 741 |
|
| |
|
|
| 07 Nov 2011 04:28 PM |
@electric
forgot close parenthesis |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 04:29 PM |
| @pompey - Ah, yes, thank you. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 07 Nov 2011 04:34 PM |
@electric
So you have to say the method? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 07 Nov 2011 04:55 PM |
| @miz - Maybe no other brick touches it? :/ |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 07 Nov 2011 04:57 PM |
| @king - You just like repeated what I've been saying. :P |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|