[Studio Beta] Collections
Key Takeaways
Collections are now available in Studio Beta to help you easily manage groups of game objects. This feature automatically connects and disconnects your code to instances based on live queries, reducing manual boilerplate and memory leaks.
Enable it via the Beta Features tab in Roblox Studio.
Hey Creators,
Collections are now available as a Studio Beta. Collections build on CollectionService, the same service you already use for tags, and add a new way to group instances and run code on them.
Collections are designed to:
• Make it easier to write code for streaming
• Extend the behavior of CollectionService to support more ways of grouping instances
• Reduce the amount of boilerplate needed with CollectionService today
What are Collections?
A Collection is a group of instances defined by a live query. When an object matches your query, it joins the Collection automatically. When it stops matching, it leaves. You bind your logic to the whole group once, and the engine handles the background tracking for you.
Example: Kill Brick
Here’s an example of a kill brick made with collections:
-- A Collection of every BasePart named "KillOnTouch"
local killBricks = CollectionService:CreateCollection("BasePart#KillOnTouch")
-- OnAdded runs once for each part as it joins the Collection
function killBricks.OnAdded(brick: BasePart)
brick.BrickColor = BrickColor.new("Neon orange")
brick.Material = Enum.Material.Neon
end
-- Bind any event by name, using the "On" prefix
function killBricks.OnTouched(brick: BasePart, otherPart: BasePart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
OnAdded runs once for each part as it is added to the collection, turning every kill brick neon orange. OnTouched connects to each part’s Touched event for you; no need to call :Connect yourself. If another part gets added to the collection later, all registered events are connected…