Help with making debounce or something to prevent the gui from always showing

I have a super simple script that when you touch a part it pops a gui up (using it as a jumpscare)

I got it to work (yayy!) but I want to make it so if the player touches it again it wont show until a specific amount of time or never showing again lol.

local Popup = script.Parent.Parent.PopUp1

Popup.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.JumpscareFolder.Jumpscare1.Spook.Visible = true
		wait(1.5)
		plr.PlayerGui.JumpscareFolder.Jumpscare1.Spook.Visible = false
	end
end)

thanks if anyone can help :slight_smile:

With debounce:

local Popup = script.Parent.Parent.PopUp1
local db = false

Popup.Touched:Connect(function(hit)
if not db then
db = true
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.PlayerGui.JumpscareFolder.Jumpscare1.Spook.Visible = true
		wait(1.5)
		plr.PlayerGui.JumpscareFolder.Jumpscare1.Spook.Visible = false
	end
wait() -- seconds until it is allowed to touch again
db = false
end)

debounce

Thanks you!!

appreciate the help :smiley: