New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to not damage the same player twice ?

Asked by
Zuraax 45
3 months 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 — 3mo
0
What do you mean ? Zuraax 45 — 3mo
0
a debounce TheluaBanana 883 — 3mo
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 — 3mo
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 297 — 3mo

Answer this question