Hello, my question is why Walkspeed in Humanoid wont change when I press the can, so the script is :
function onClicked(part) h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then h.WalkSpeed = 21 script.Parent.Parent.Parent.REDBULL1:Destroy() end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
And the script is in LocalScript... So it wont work, please help !
If you take a look at the documentation for the MouseClicked event you will read the following.
Parameters:
playerWhoClicked
Type: Player
This indicates that when connecting to the event with a function, the first parameter will be the player that clicks the MouseDetector and not any part (think about, does a player click a MouseDetector with their head, torso, or leg?). That means we won't have to check for a humanoid like you do with the following.
h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then
Instead, humanoid will be defined relative to the player.
function onClicked(theplayer) -- I renamed the variable so it's more clear what it actually is. h = theplayer.Character:FindFirstChild("Humanoid") h.WalkSpeed = 21 script.Parent.Parent.Parent.REDBULL1:Destroy() end script.Parent.ClickDetector.MouseClick:connect(onClicked)
The MouseClick event must be handled by a Script.