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

Variables and their Children?

game.Players.PlayerRemoving:connect(function(player)
local bob=player.Name
	for i,v in pairs (workspace.Population.Worker.bob:GetChildren()) do
		v.Parent=workspace.Population.Unemployed
		workspace.Population.Worker.bob:Destroy()
	end
end)

The reason I am using a variable is because bob is supposed to be the name of a player and I want to make it so that bob will have all its children become unemployed and the model itself to be destroyed but it keeps saying bob is not a valid member of model.

1 answer

I changed the .bob to [bob], does that fix your code?

game.Players.PlayerRemoving:connect(function(player)
local bob=player.Name
    for i,v in pairs (workspace.Population.Worker[bob]:GetChildren()) do
        v.Parent=workspace.Population.Unemployed
        workspace.Population.Worker[bob]:Destroy()
    end
end)

2 comments

1

Line 5 should also be [bob].

0

o yes. thx

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