I have created a script that launches a localscript that creates a gui on the players screen, I have also attempted to create a debounce system to stop the players screen from being spammed with the same GUI, however it only allows the script to be run once, and never again. which is not what I needed, I do not know why the script does not run again after the player touches it a second time.
Have I done the debounce wrong? or is it something else?
local event = Instance.new("RemoteEvent",game.ReplicatedStorage) event.Name = "conversation started" local debounce = false script.Parent.Touched:connect(function(hit) if not debounce then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then debounce = true event:FireClient(player,player) end end end) debounce = false
You want to ensure that you are changing the debounce
back to false as soon as you are done with whatever you are doing in the event. So you simply need to check at the beginning of the function as to whether the debounce
is true and if so, return and stop the function immediately. From there, set it to true and do the work, and at the end of the work, set it to false. Done!
local event = Instance.new("RemoteEvent",game.ReplicatedStorage) event.Name = "conversation started" local debounce = false script.Parent.Touched:connect(function(hit) if debounce then return end debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then event:FireClient(player,player) end debounce = false end)
You'll then have to, in your client-side LocalScript, just make sure that the GUI doesn't exist before you create a new one.