I put debounce in my code, but it wont work and it gives the tool multiple times.
01 | local buttonPressed = false |
02 |
03 | script.Parent.Touched:connect( function () |
04 | if not buttonPressed then |
05 | print ( "BPT" ) |
06 |
07 | buttonPressed = true |
08 | print ( "BPI" ) |
09 |
10 | game.Lighting.ClassicSlingshot:clone().Parent = game.Players.LocalPlayer.Backpack |
11 | print ( "Hi" ) |
12 |
13 | buttonPressed = false |
14 | print ( "BPF" ) |
15 |
16 | end |
17 | 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;
01 | local variable = false |
02 | local part = script.Parent |
03 |
04 | part.Touched:Connect( function (hit) |
05 | local hum = hit.Parent:FindFirstChild( "Humanoid" ) |
06 | if hum ~ = nil and variable = = false then variable = true |
07 | hum:TakeDamage( 20 ) |
08 | end |
09 | wait( 5 ) |
10 | variable = false |
11 | end ) |
I'll help you out by correcting your script as well, you can thank me later.
01 | local buttonPressed = false |
02 |
03 | script.Parent.Touched:connect( function () |
04 | if buttonPressed = = false then |
05 | buttonPressed = true |
06 | game.Lighting.ClassicSlingshot:clone().Parent = game.Players.LocalPlayer.Backpack |
07 | wait( 5 ) |
08 | buttonPressed = false |
09 | end |
10 | end ) |