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

Trying to remove children?

I'm trying to make a script that :GetChildren then removes them from the local camera.

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			c = game.Workspace.CurrentCamera:GetChildren()
		end)
	end)
end)

1 comment

0

You could just say game.Workspace.CurrentCamera:ClearAllChildren().

1 answer

✓ Accepted answer

The CurrentCamera is only available from LocalScripts.

As a consequence, it is not meaningful for a script to use both CurrentCamera and the PlayerAdded event.


Instead, wherever it is that you put objects into the camera, begin that script by clearing them out.

Alternatively, just have a separate LocalScript in the PlayerGui that clears it out (run each time they spawn, so as long as everything else waits a bit, it should be fine)

-- A LocalScript
c = game.Workspace.CurrentCamera:GetChildren()
for _, child in pairs(c) do
	child:Destroy()
end

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