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

How to get object that lost child and then rename it?

for _, object in pairs (game.Workspace.Model:GetChildren()) do
	object.ChildRemoved:Connect(function(Child)
		Child.Parent.Name = "OtherName"
	end)
end

If I trying this error pops-out: attempt to index nil with 'Name'

I have many objects and when one object lost child I need to rename it.

1 answer

✓ Accepted answer

Your script is trying to rename a value that was removed. If you are trying to rename the object that the child is removed from, your function would look like this:

object.ChildRemoved:Connect(function()
     object.Name = "OtherName"
end)

Now if this isn't what you are trying to do, please let me know.

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