Hi, I'm currently working on the combat system for my game and I've encountered a strange problem. Basically, I have a listener for tool.Activated, but when I set the debounce later in the script it doesn't work? No error is thrown.
Footnote: I don't know if this is what's causing the problem, but the code for setting the debounce is below the code for checking it. I wouldn't have thought it would cause any issues so I didn't bother with moving it around.
Code for checking the debounce:
tool.Activated:Connect(function()
if debounce == false and swingTrack.IsPlaying == false then
swingTrack:Play()
end
end)
Code for setting the debounce:
rangeKillbrick.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local chr = hit.Parent
if hit.Parent ~= tool.Parent and hum ~= nil and swingTrack.IsPlaying and debounce == false then
local plr = game.Players:GetPlayerFromCharacter(chr)
if plr.Team == game.Teams.Infected then
debounce = true
hum.Halth = hum.Health - dmg
wait(2)
debounce = false
end
end
end)

1 comment
In line 4, try hit.Parent.Name ~= tool.Parent.Name instead of that.