You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? i want the speed pad that i made in my game to stop after a couple of seconds
- **What is the issue? i want to stop after a while and it wont
-- script.Parent.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 50
end)
there is my script
Add a wait
in the script then set their walkspeed back to normal.
I also suggest adding a debounce and checking if the humanoid actually exists.
Here is some example code:
local debounces = {}
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
--// The part hitting the script's parent might not be a character so we should check.
if (humanoid and not debounces[humanoid]) then
--// we also have a debounce so an individual character should only be able to
--// get speed every 10 seconds (immediately after their speed is over)
debounces[humanoid] = true
humanoid.WalkSpeed = 50 --// new speed
wait(10) --// wait 10 seconds
humanoid.WalkSpeed = 16 --// default walkspeed
debounces[humanoid] = nil
end
end)
1 Like
it ended up not working idk whats wrong
local debounce = false
local theWait = 5 --Change to whatever you want.
local newSpeed = 50
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not debounce then
debounce = true
hit.Parent.Humanoid.WalkSpeed = 50
wait(theWait)
hit.Parent.Humanoid.WalkSpeed = 16 --16 is default walkspeed
debounce = false
end
end
end)
If you meant that the event should not work anymore then you can store it in a variable.
local TouchEvent = script.Parent.Touched:Connect(function(hit)
--whatever you want
end)
wait(10) --Wait 10 seconds until it dont work no more
TouchEvent:Disconnect()
2 Likes
Thank you works!
(30 Characters)
1 Like