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

How to damage multiple people?

Asked by 3 years ago

I know its due to Debounce but if I remove Debounce it damages players multiple times. How to fix?

here code:

local remote = game.ReplicatedStorage.BarrierBeam
local Debounce = false

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)
            if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
                if Debounce == false then
                Debounce = true
                hit.Parent.Humanoid:TakeDamage(35)          
                wait(2)
                    Debounce = false  
                    end
            end
    end)
end)

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

You can use a table (dictionary) and index the table with the player's name or user id:

local remote = game.ReplicatedStorage.BarrierBeam
local Debounce = {} -- table

remote.OnServerEvent:Connect(function(plr,mouseaim)
    if not Debounce[plr.UserId] then 
        Debounce[plr.UserId] = false -- initialize
    end
    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)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
            if Debounce[plr.UserId] == false then
                Debounce[plr.UserId] = true
                hit.Parent.Humanoid:TakeDamage(35)          
                wait(2)
                Debounce[plr.UserId] = false  
            end
        end
    end)
end)
0
If I implement this to all my abilities; would it work if a player gets attacked by multiple abilities at the same time>? monsterdanger16 13 — 3y
1
If you use a different table for each ability it should work just fine appxritixn 2235 — 3y
Ad

Answer this question