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

How to not damage the same player twice ?

Asked by 4 years ago

Hi, i've made a script that creates a blast in front of the player. When the ball appears and grows, it's supposed to deal damage to people (or entities) it encounters. I used the ":Touched()" function so it detects every part that touch the blast and it deals damage to its owner. However, as it detects many parts from the same player, it damages the same player more than once. Here's the script :

local transparency = 0
local blast = Instance.new("Part", game.Workspace)
blast.Shape = "Ball"
blast.CanCollide = false
blast.Anchored = true
blast.Size = Vector3.new(0.5,0.5,0.5)

blast.Touched:connect(function(hit)
    for _, char in pairs(game.Workspace:GetChildren()) do
        if char:FindFirstChild("Humanoid") then
            if hit.Parent == char or hit.Parent.Parent == char then
                if hit.Parent.Name ~= player.Name and hit.Parent.Parent.Name ~= player.Name then
                    char.Humanoid:TakeDamage(50)
                end
            end
        end
    end
end)


for i=1,14 do
    transparency = transparency + 0.072
    blast.Transparency = transparency
    blast.Size = blast.Size + Vector3.new(1.5,1.5,1.5)
    wait()
end
0
Use a debounce. Thesquid13 301 — 4y
0
What do you mean ? NotZuraax 68 — 4y
0
a debounce TheluaBanana 946 — 4y
0
Basically, add a wait() at the end of the script that detects/deals damage to make sure it only happens the first go. NIMI5Q -2 — 4y
0
you could make a table and put every person the blast hits name in it and loop through it and if the name of the collided player is not in the table, add e name and their name and do damage to them. I have no idea performance wise how good this would work though the8bitdude11 358 — 4y

Answer this question