Script.Parent:GetChildren().Changed?

I’m currently trying to detect when the contents or the children of the script.Parent change, but that never worked. So I did:

while wait(0.1) do
	local items = script.Parent:GetChildren()
	wait(0.1)
	local items2 = script.Parent:GetChildren()

	if items ~= items2 then
		Distribute()--Fires another function
	end
end

This never worked because it compares the TableID(I Thing that’s whats its called) instead of seeing if the contents changed. So what would be the best way to detect the change of contents.

1 Like

Always look for an event-based solution before resorting to loops like that, as they can become a major source of lag.

script.Parent.ChildAdded:Connect(function(instance)
    print("Added", instance)
end)
script.Parent.ChildRemoved:Connect(function(instance)
    print("Removed", instance)
end)

Also, GetChildren creates a completely new table every time.

1 Like

Completely forgot about ChildAdded/Removed. Thx