#Collection Serv and GetChildren/GetDecendants
1 messages · Page 1 of 1 (latest)
Collection service is primeraly used for gettagged I believe, so in a folder you might have, item1,item2,item3; get children would get all three but if you have a tagg called odd on the 1 and the 3 collectionService:gettagged('odd') would return 1 and 3
As Flya mentioned, CollectionService is used for Tagged objects.
e.g
You could have many parts across your workspace that should kill a player, if you go into the properties of these parts and at the very bottom add "KILL_PART" as a tag, you can utilise:
CollectionService = game:GetService("CollectionService")
local killParts = CollectionService:GetTagged("KILL_PART")
-- Will return {Part, Part2, ... etc}
Whereas if you have a Model with parts inside it, GetChildren can be used.
local model: Model = game.Workspace.SomeModel
local tableOfChildren = Model:GetChildren()
-- Will return all children of the model {Part, Part2, SurfaceGUI, ... etc}
CollectionService means you don't have to manually find those parts, or group them in a specific place to iterate over
GetChildren just returns all children of any instance such as a model.
This is especially important when you want to move or refactor the locations of some parts, without breaking functionality, as GetTagged will always get that object as long as the tag stays on the object, no matter the location.
Ohhhh