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

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

Asked by 5 years ago

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.

0
Dont forget to accept my answer if it helps out. User#24403 69 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago

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.

Ad

Answer this question