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

PlayerGui is not a member of Player?

while true do
	wait(0.1)
	for i,v in pairs(game.Players:GetPlayers()) do
		wait(0.1)
		
	v.PlayerGui.ScreenGui.Chillers.Text="Unemployed: 		"..game.workspace.PopulationFigures.ChillersHowMuch.Value

		v.PlayerGui.ScreenGui.People.Text="Total People "..game.workspace.PopulationFigures.PeopleHowMuch.Value

		v.PlayerGui.ScreenGui.Workers.Text="Other Workers "..game.workspace.PopulationFigures.WorkersHowMuch.Value

		v.PlayerGui.ScreenGui.TooYoung.Text="Too young to work "..game.workspace.PopulationFigures.TooYoungHowMuch.Value
		
	end
end

This always says playerGui is not a valid member of player when I run it on a server. This is a local script in screengui any help please. FE is disabled. It says the mistake is on line 6.

1 comment

1

not everything is loaded at the start of the game. Try v:WaitForChild("PlayerGui") for all od the part that require the PlayerGui.

2 answers

As Bulvyte said, you could use WaitForChild. I prefer to use FindFirstChild in this scenario as it could be down to an exploiter or another script changing the name of the player's PlayerGui resulting in it not being found. Having WaitForChild in this scenario would cause it to wait forever or until it changes back. Just search for it, if it's not there pass on to the next player. The code should be:

 --WaitForChild waits for the PlayerGui then fires the lines.
while true do
    wait(0.1)
    for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("PlayerGui") ~= nil then -- If they have an instance called PlayerGui
	        wait(0.1)
	
	    v.PlayerGui.ScreenGui.Chillers.Text="Unemployed:        "..game.workspace.PopulationFigures.ChillersHowMuch.Value
	
	        v.PlayerGui.ScreenGui.People.Text="Total People "..game.workspace.PopulationFigures.PeopleHowMuch.Value
	
	        v.PlayerGui.ScreenGui.Workers.Text="Other Workers "..game.workspace.PopulationFigures.WorkersHowMuch.Value
	
	        v.PlayerGui.ScreenGui.TooYoung.Text="Too young to work "..game.workspace.PopulationFigures.TooYoungHowMuch.Value 

		end
    end
end

Hope this helps, if it does, please vote it up and accept it as the answer.

Try this:

 --WaitForChild waits for the PlayerGui then fires the lines.
while true do
    wait(0.1)
    for i,v in pairs(game.Players:GetPlayers()) do
        wait(0.1)

    v:WaitForChild("PlayerGui").ScreenGui.Chillers.Text="Unemployed:        "..game.workspace.PopulationFigures.ChillersHowMuch.Value

        v:WaitForChild("PlayerGui").ScreenGui.People.Text="Total People "..game.workspace.PopulationFigures.PeopleHowMuch.Value

        v:WaitForChild("PlayerGui").ScreenGui.Workers.Text="Other Workers "..game.workspace.PopulationFigures.WorkersHowMuch.Value

        v:WaitForChild("PlayerGui").ScreenGui.TooYoung.Text="Too young to work "..game.workspace.PopulationFigures.TooYoungHowMuch.Value 

    end
end

I just added the WaitForChild("PlayerGui") for every line. It waits for the PlayerGui to be valid then executes.

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