Hello there! I made a script which opens a gui.
Unfornatuely it gives me the gui several times.
I looked through the devforum for a solution but I am not able to find anything which worked on my script.
I already checked this article out: Debounce – When and Why but I just don’t understand why it is not working on my script.
Could someone explain me how I use debounce and how I would use it on this script?
wait(1)
local buttonPressed = false
local gui = script.DrinkGui
function onTouched(p)
if not buttonPressed then
buttonPressed = false
end
if p and p.Parent and game.Players:FindFirstChild(p.Parent.Name) ~= nil then
local player = game.Players:FindFirstChild(p.Parent.Name)
if player.PlayerGui:FindFirstChild("ShopGui") == nil then
local newgui = gui:Clone()
newgui.Parent = player.PlayerGui
wait(2)
buttonPressed = true
end
end
end
script.Parent.Touched:Connect(onTouched)