How would I be able to create a debounce in this script?

Hello! I am the secondary scripter for my next game. I found a bug that will affect the next thing to finish the teleporter elevators.

The Problem
image

The Code

local Popup = script.Parent.Leave
local Ready = true
function onTouch(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil and Ready == true then
		Ready = false
		local plyr = game.Players:FindFirstChild(h.Parent.Name)
		local c = Popup:clone()
		c.Parent = plyr.PlayerGui
		
		local newPlayer = Instance.new("ObjectValue")
		newPlayer.Parent = script.Parent.Players
		newPlayer.Name = plyr.Name
		newPlayer.Value = plyr
		
		Ready = true
	end
end

script.Parent.Touched:connect(onTouch)

If you know a fix, please let me know.
WE
(Not scripted by me, scripted by the primary scripter who is trying to help)

Well as on how i see it, you’re telling the script that if something is true to set it to false and then set it to true, your friend with this is the :wait() function, just put a wait function between the ones that turn ready to false and then to true, also set the wait time on how you desire.

Why didn’t I think of that…
I was trying a lot of advanced things.
I feel so stupid now.

Thanks.

1 Like