Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Debounce for on touched event not working??

Asked by
pie9909 18
4 years ago

Not sure what's going on here but it could just be me being dumb, my debounce isn't working. other than that everything is working fine

is it because of how I placed the debounce?

01game.Players.PlayerAdded:Connect(function(player)
02    script.Parent.Touched:Connect(function(hit)
03 
04        local char = hit.Parent
05        local hum = char:FindFirstChild("Humanoid")
06 
07        local debounce = false
08 
09        if hum and not debounce then
10 
11 
12            local players = game:GetService("Players")
13            local player = players:GetPlayerFromCharacter(char)
14            local pack = player.Backpack
15            local findSword = pack:FindFirstChild(player.Name.."'s sword")
View all 45 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

Yes, it IS because of how the debounce is placed. debounce is always set to false when the event fires. You need to declare the variable outside the events.

0
Ohh i see, alright thanks a ton pie9909 18 — 4y
Ad

Answer this question