I made a part that shows gui on touch with the help of @youtubemasterWOW , but I tried to add Debounce to it and its not working. I am pretty sure that I wrote it down right but I didn't get any errors but as I said, it didn't work. can someone help me? here is my code:
local debouce = false local gui = game.ReplicatedStorage.EasyGUI local frame = gui.Frame local function onTouched(hit) if not debouce then debouce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local clone = gui:Clone() clone.Parent = player.PlayerGui wait(1.5) debouce = false end script.Parent.Touched:Connect(onTouched) end end
I need help on this a lot so that the players in my game don't find it annoying to keep on pressing to close button on the gui.
local debouce = false local gui = game.ReplicatedStorage.EasyGUI local frame = gui.Frame local function onTouched(hit) if not debouce then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player.PlayerGui:FindFirstChild("EasyGUI") == nil then debounce = true local clone = gui:Clone() clone.Parent = player.PlayerGui wait(1.5) debouce = false end end end end script.Parent.Touched:Connect(onTouched)
The issue you had was that you were activating the debounce for all parts. But you set the debounce to false inside the "if player" meaning that any non-player part would trigger it and keep the debounce as true.
Make sense?