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

Can someone explain CollectionService?

Asked by 5 years ago

All I understand about it is that you assign tags to instances and then you're able to get all the instances that have that tag. I'm trying to make a game that involves users interacting with objects and I want "press e to drive" jailbreak-esque billboard guis that make action menus pop up, is that an appropriate use of CollectionService?

Can someone give me an example of how to use collectionservice because the wiki one really doesn't make it that clear how to assign a tag to an instance.

0
"Can someone give me an example of how to use collectionservice because the wiki one really doesn't make it that clear how to assign a tag to an instance." climethestair 1663 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Personally for my game (survival) I used the CollectionService for three categories of objects. I have Items, Buildings, and Resources. When I load the game, or interact with the objects - I use one script, but branch it off into different variations of the same action based on what tag the object i'm interacting with has.

For example for Items, I make it so you can pick them up with 'E'.

Resources, I am able to hit and destroy - and they drop things.

Buildings, I can interact with them or destroy them.

I find it especially useful because I can just go through the list of Instances with the same tag instead of going through the entire workspace and checking if they have the tag or not.

To add a tag: CollectionService:AddTag(object, "TagName")

So I believe that you COULD use the CollectionService for what your trying to do, but I wouldn't think it's really necessary.

Ad

Answer this question