The only problem I noticed at first glance was the checking of the Name property's value.
Also, since you want the hit to be from a part, i added a check for hit's ClassName using the
IsA method.
If the first argument is false or nil (the name isn't 'XP' in this context), the or operator returns the second argument, which is a string (true, because it isn't nil or false).
if (false or true) then
if (nil or true) then
If the first argument is true, it is returned and the second argument is ignored.
if (true or true) then
The statement then only checks for whether or not the Name is XP. Here's are examples on how to work around this
- Check by typing out the property you are assessing after the
or
script.Parent.Touched:connect(function (hit)
if hit:IsA('BasePart') then
if hit.Name == 'XP' or hit.Name == 'Gold' then
warn('Destroy')
else
end
end
end)
- Tables
Names = {'XP', 'Gold'}
script.Parent.Touched:connect(function (hit)
if hit:IsA('BasePart') then
if Names[hit.Name] then
warn('Destroy')
else
end
end
end)
1 comment
This is my 100 Answer.