Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to remove children?

Asked by 10 years ago

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)
0
You could just say game.Workspace.CurrentCamera:ClearAllChildren(). ChipioIndustries 454 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
Ad

Answer this question