Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I add debounce to this short script?

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)

1 comment

0

dude try google first, and this is like the fourth time u have asked a question like this.

1 answer

✓ Accepted answer

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)

8 comments

0

very well explained, don't know why it isnt marked as answer

0

very well explained, don't know why it isnt marked as answer

0

uh is the site broken its spamming comments

0

uh is the site broken its spamming comments

0

uh is the site broken its spamming comments

0

uh is the site broken its spamming comments

0

uh is the site broken its spamming comments

0

uh is the site broken its spamming comments

This discussion is preserved as it was. New answers, comments, and votes are closed.