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)
line 8 in setting debounce not hum.halth but hum.health
put this:
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.Health = hum.Health - dmg wait(2) debounce = false end end end)
local debounce = false 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.:GetService("Teams").Infected then debounce = true hum.Health = hum.Health - dmg wait(2) debounce = false end print(debounce) end end)
Solved this one myself. Put the debounce set in the wrong function, it only would have set a cooldown if it hit an enemy. Just needed to move it from checking if it hit an enemy to the tool being activated in it of itself.