Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I fix this simple ChildRemoved() function?

This script is supposed to make the parts of a tree un-anchored if one of the parts is removed, but the script doesn't work and I don't get any error messages... Any idea what I did wrong? I'm thinking it has to do with line 5 but i'm not sure. Thanks guys!

local Tree = script.Parent
local parts = Tree:GetChildren()
local Wood = Tree:FindFirstChild("Med Wood")
-----------------------------------------------------------------
Tree.ChildRemoved:connect(function()
wait(2) 
	for index, child in pairs(parts) do
		if child:isA("Basepart") then child.Anchored = false
		end
	end
end)

1 answer

✓ Accepted answer

When ChildRemoved event gets fired, it's not removed yet, so you can use its properties etc. But if you wait for two seconds like you did in sixth line, child will get removed and probably script will not work.

This discussion is preserved as it was. New answers, comments, and votes are closed.