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.
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.