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

[Solved] Why does this group damaging projectile hit multiple times?

Asked by 5 years ago
Edited 5 years ago

The projectile is a fireball and the idea is to create a table of enemies that are already hit, make sure the enemy is not in the table and damage them and add them to the table if they are hit.

local alreadyHit = {}
ball.Touched:Connect(function(hit)
    if hit.Parent and hit.Parent ~= char then
        if not isInTable(alreadyHit, hit.Parent) then
            touch.burn(hit.Parent, assets:FindFirstChild("PurpleFlameParticles"):Clone(), 1.5, .5)
            alreadyHit[#alreadyHit + 1] = hit.Parent

        end
    end
end)

Here is the isInTable function:

function isInTable(tableValue, toFind)
    local found = false
    for _,v in pairs(tableValue) do
        if v == toFind then
            found = true
            break;
        end
    end
    return found
end

Any help is greatly appreciated!

0
Touched events are weird. Try adding a debounce. Jexpler 63 — 5y

Answer this question