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

How can I debounce a script until the player stops and starts touching the basepart again?

The question is rather long but I'll try to cut to the chase:

I've been experimenting with debounces and I'm interested in creating a script that affects a GUI so that the script only runs once while being touched and cannot run again until the player is detected to have stopped and started touching the BasePart again.

I'll attach my current script if it helps:

part = game.Workspace.ZONEMeridonWoodlands local debounce = false

part.Touched:connect(function(hit)

if not debounce then

debounce = true

print(hit.Name .. " was touched by the part!")

end end)

Currently this script works to only play the script once however it doesn't appear to play the script when the BasePart is touched a new time. The full original script is much longer but all that was removed was a sizeable midsection of making very small changes to the properties of the GUI.

Any advice is appreciated. I'll try to stay active so I can answer any questions.

2 answers

You forgot to set the debouce to false after it was touched once:

part = game.Workspace.ZONEMeridonWoodlands local debounce = false

part.Touched:connect(function(hit)
if not debounce then
debounce = true
print(hit.Name .. " was touched by the part!")
wait(0.1) -- replace the time with the amount of time you want
debouce = false
end end)

Try this

local part = workspace:WaitForChild("ZONEMeridonWoodlands")
local debounce = false

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true
			print(hit.Name.." was touched by the part!")
			wait(4)
			debounce = false
		end
	end
end)

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