Hey I was wondering how I'd a debounce to this short script. Any help would be great!
local frozen = false function slowdown (hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid.WalkSpeed = 0 frozen = true end local hum = hit.Parent.Humanoid function normal() wait(5) hum.WalkSpeed = 16 end hum.Changed:connect(normal) end script.Parent.Touched:connect(slowdown)
Hello.
It's simple. Define a boolean value. At the beginning of the script check the boolean value. If it is true, then return nothing and stop the script, else, continue running the script. After you set the humanoid speed to 0, set the boolean value to true, so the code won't run until the boolean value it's false. Wait AMOUNT OF TIME then set the boolean to false.
If I was you, I'd wait 1 or 2 more seconds before setting the boolean to false, after you set humanoid's speed back to normal, to give the character time to get away from the part. Here's an example:
local Frozen = false function Slowdown(hit) if Frozen then return end if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid.WalkSpeed = 0 Frozen = true wait(5) hit.Parent.Humanoid.WalkSpeed = 16 wait(2) Frozen = false end end script.Parent.Touched:Connect(Slowdown)