I'm trying to make a collectible system that makes a sound when all the items within a group have been found. This is what I have...
local Notes = script.Parent.Notes local Sound = script.Parent.Sound
if Notes:GetChildren() == 0 then Sound:Play() end
Any help would be greatly appreciated!! :)
You would need to use the #
operator. This operator gets the length of a table. Since GetChildren() returns a table we can simply put the #
operator in front of Notes:GetChildren()
so it would look like #Notes:GetChildren()
. You can then check if the length of this table is equal to 0.
local Notes = script.Parent.Notes local Sound = script.Parent.Sound if #Notes:GetChildren() == 0 then Sound:Play() end
Obviously the code above won't constantly check if the length of the table is equal to 0, so you would need to use a loop or an event to check. For example, you can use the ChildRemoved event so when something gets removed from "Notes" it will check if the length of the table is equal to 0.
local Notes script.Parent.Notes local Sound = script.Parent.Sound Notes.ChildRemoved:Connect(function() if #Notes:GetChildren() == 0 then Sound:Play() end end)