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

Debounce not working. Kills player instead of damage. How do i fix it?

Asked by 2 years ago

I made an ability that creates a beam and damages the player but instead of 35 dmg it kills them.

Here is the Code:

local remote = game.ReplicatedStorage.BarrierBeam

remote.OnServerEvent:Connect(function(plr,mouseaim)
    local parts = game.ServerStorage.Classes.BarrierMaster
    local BeamLoc = parts.BarrierBeam
    local Beam = BeamLoc:Clone()
    Beam.Parent = workspace
    Beam.CFrame = CFrame.new(mouseaim)
    local dmg = game.Workspace.BarrierBeam.Damagepart
    game.Debris:AddItem(Beam, 1.7)
    wait(1.5)
    dmg.Transparency = 0.6
    dmg.Touched:Connect(function(hit)
        for i,v in pairs(workspace:GetChildren()) do
            local Debounce = false
            if hit.Parent:FindFirstChild("Humanoid")and Debounce == false and hit.Parent.Name ~= plr.Name then
                Debounce = true
                hit.Parent.Humanoid:TakeDamage(35)
                wait(2)
                Debounce = false                                            
                        end
        end
        end)
end)

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
    dmg.Touched:Connect(function(hit)
        for i,v in pairs(workspace:GetChildren()) do
            local Debounce = false -- you are setting the debounce every time it touches something. This line should be next to "local remote" on line 2 above the whole function. Then you can remove this line here
            if hit.Parent:FindFirstChild("Humanoid")and Debounce == false and hit.Parent.Name ~= plr.Name then
                Debounce = true
                hit.Parent.Humanoid:TakeDamage(35)
                wait(2)
                Debounce = false                                            
                        end
        end
        end)
end)
0
ty monsterdanger16 13 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Maybe At line 18 put hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 35

0
It still kills them monsterdanger16 13 — 2y

Answer this question