I put debounce in my code, but it wont work and it gives the tool multiple times.
local buttonPressed = false script.Parent.Touched:connect(function() if not buttonPressed then print("BPT") buttonPressed = true print("BPI") game.Lighting.ClassicSlingshot:clone().Parent = game.Players.LocalPlayer.Backpack print("Hi") buttonPressed = false print("BPF") end end)
Your script doesn't correctly define the debounce as it's supposed to be. The correct way would be to create an if statement making sure that you clarify if the variable is false, then you make it true. Once that variable is true, until it's false again it should not be able to work.
Example;
local variable= false local part= script.Parent part.Touched:Connect(function(hit) local hum= hit.Parent:FindFirstChild("Humanoid") if hum ~= nil and variable == false then variable = true hum:TakeDamage(20) end wait(5) variable = false end)
I'll help you out by correcting your script as well, you can thank me later.
local buttonPressed = false script.Parent.Touched:connect(function() if buttonPressed == false then buttonPressed = true game.Lighting.ClassicSlingshot:clone().Parent= game.Players.LocalPlayer.Backpack wait(5) buttonPressed = false end end)