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

Tool cooldown (debounce) failing to work. Why does this happen?

Asked by 2 years ago

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)
0
In line 4, try hit.Parent.Name ~= tool.Parent.Name instead of that. NotThatFamouss 605 — 2y

3 answers

Log in to vote
1
Answered by 2 years ago

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)
0
Didn't fix it? PufferfishDev 49 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
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)
Log in to vote
0
Answered by 2 years ago

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.

Answer this question