Title is self-explanatory. Trying to use Instance:HasTag() directly on an Instance succeeds, but in the context of running a loop over some instances to see if any one Instance has a specific tag, the loop will succeed and then error. This is somewhat confusing and peculiar behavior that I don’t understand.
The method call you want here is CollectionService:GetTagged(<tag>), which will not run into this issue and be much more efficient than what you were trying to do as a bonus.
Yes, I know. I’m reporting this engine bug specifically because it errors when I try to use it in this instance. I know it seems superfluous, but a bug is a bug
I wouldn’t necessarily say gettagged is a better way of checking if something has a tag before runtime. Especially in the command bar, because you’d have to add a for loop in a for loop as it returns an array of objects. Whereas hastag will just print the object that has the tag. Much more simpler. A good way to check if something in the whole game has a tag.
I don’t know if you figured out the solution yet as I don’t have the best english but the documentation says hastag requires two arguments, the first one is the instance you need to check and the second is the name. (If you do it through collectionservice)
However if you just do Instance:HasTag(“Name”) it only requires one argument, and that’s just the name.
Fair, you could early-out on some combination of HasTag checks.
If you just want to find out whether anything has a given tag there’s also a better way to do that by calling table.find(CollectionService:GetAllTags(), <tag>).