Hello all, me again. Have another debounce issue, and don't understand as to why this isn't working properly! Looking to make a GUI pop up if player doesn't have the proper leaderstat value, or more than the proper leaderstat value!
Here is my SCRIPT and the GUI is the child of the SCRIPT
Any and ALL HELP is appreciated!
local debounce = false script.Parent.Touched:Connect(function(hit) debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) local lvl = player.leaderstats.Door1 if player and lvl.Value > 1 and not player.PlayerGui:FindFirstChild('buydoor') then script.Parent.CanCollide = false else local cloneui = script.buydoor:Clone() cloneui.Parent = player.PlayerGui cloneui.Frame:TweenPosition(UDim2.new(0.25,0,0.2,0)) debounce = false end end)
Debounces are used to regulate how many times an event can be fired. In your code you are currently not regulating anything, you're just changing a variable.
I modified your script, added comments around the debounce area so you can read those if you want a better understanding of what I changed.
local debounce = false script.Parent.Touched:Connect(function(hit) if debounce == true then return end --//If debounce is true, then return nil debounce = true --//Turn the debounce to true to make sure it doesn't fire the event again during the execution of the code below local player = game.Players:GetPlayerFromCharacter(hit.Parent) local lvl = player.leaderstats.Door1 if player and lvl.Value > 1 and not player.PlayerGui:FindFirstChild('buydoor') then script.Parent.CanCollide = false else local cloneui = script.buydoor:Clone() cloneui.Parent = player.PlayerGui cloneui.Frame:TweenPosition(UDim2.new(0.25,0,0.2,0)) end debounce = false --//We have to put this at the end to make sure the debounce becomes false again and the event is activated once more end)
you didnt add the if statement for the debounce you just had a variable named debounce laying around doing nothing and your just setting it to true and false
From what I've been told, you shouldn't do that. This is what I was told to do:
if not debounce then debounce = true -- or this: if debounce = false then debounce == true