Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is It Possible to Have a Blacklist for a Touched Event?

I am using a script for a sword that makes it so whenever the blade touches an enemy, the enemy will be damaged. However, I have a part surrounding the enemy called "Radius" which is to detect when the player gets near the enemy. This causes the sword to hit the radius part instead of the enemy.

So would it be possible to have a blacklist for a touched event to ignore certain parts, and how would I be able to do it? Thanks.

1 comment

0

Dont forget to accept my answer if it helps out.

1 answer

✓ Accepted answer

You can use a dictionary that contains the names of the parts you want to blacklist. Example

local blacklisted = {
    Radius = true
    -- # feel free to add more to the blacklist
}

part.Touched:Connect(function(other)
    if blacklisted[other.Name] then 
        return -- # part is in blacklist, return out of function 
    end
end)

The keys would be the name of the parts to blacklist and the value to true.

If the part name is not in the dictionary it will be nil. Example

local t = {}
print(t.k)

Prints nil since the key k does not exist in t. So if the parts name is not in the dictionary the if statement's condition will not be satisfied and therefore will not prematurely end the function.

This discussion is preserved as it was. New answers, comments, and votes are closed.