Fastest and efficient method to detect certain type of cloned parts?

By detecting “certain” parts, I mean an specific type of parts that has a certain behaviour or meaning in the game.

For example, in a game I’m developing rn, I need to check for a single part that is a ground. In the game, grounds are destroyable and have an specific hardness, so I thought about adding a boolValue called IsGround, but suddenly remembered that attributes are now a thing so this question came to my mind.

The options I’ve thought about by the moment are:

  • Get tags from part using CollectionService
  • Put some string or bool value instance and check if exists
  • Use the recently added attributes and check if the attribute exists on the part
1 Like

The best method is to use CollectionService since you can get all the objects that has a tag, with CollectionService:GetTagged(tag) and you can also know when a Instance with a tag is added to the game or removed.

Also, for what you’re trying to do, that’s why CollectionService exists.

And there is a plugin which you can use to add tags to objects without scripts:

2 Likes

This should go under #help-and-feedback:building-support, this is not development discussion material.

Depending on your use case you might also be able to use collision groups to give “destroyable” objects a unique group, with identical collisions to their default group.

I haven’t tested this, but you could probably code some scripts to time how long it takes to do all those operations for 10k repetitions, and make a more informed decision (using tick() to get the time).

1 Like