Folders in 'StarterGui' not always present in player.PlayerGui at PlayerAdded

Hi,
I have a problem with my game not always saving for some players. I use Datastore 2.
On further investigation I think maybe the problem is not with the saving at all but with loading everything (from last time) when a player joins.

I have a few folders in ‘StartGui’ with the names and levels of the machines that need to spawn in a shop at startup.
image

However for ‘some’ players my playerAdded script stops (and errors) on this line of code:

local Washers = player.PlayerGui:WaitForChild("Washers")

The errors I see in the logs are:

PlayerGui is not a valid member of Player "xxx"
 ServerScriptService.DataStoreScript, line 458

Offcourse, after this the machines and levels are not loaded as the script stopped for this player.

This doesn’t happen a lot and when I was in contact with players that had this problem rejoining the game fixed it (most of the times) for them.

I tried using ‘WaitForChild’ but I also notice these errors on savind, so it means these StarterGui folders are also not created when we wait a bit longer. Somehow they just got lost?

Does anybody know how to make this more relyable?
If no solution is found I was planning to remove these folders and create the folders and StringValues on ‘playeradded’ instead of letting them be copied from StarterGui (but I find it easier to script in studio if I see the names of the scringValues in the explorer window of studio).

I hope someone can help me, I’m already struggling with this problem for more then half a year.

Kind Regards
OldEvilOne

PS: The game where I have the problem:

Maybe… I was just stupid…

I changed to code now to this in the playerAdded script:

local playerGUI = player:WaitForChild(PlayerGui)
local Washers =  playerGUI:WaitForChild(Washers)

Maybe this will help.?
(But I already had 20 of those Aha-moments the last 6 months - none helped :slight_smile: )
(we’ll see)

Didn’t help:
08:50:29.243 Infinite yield possible on ‘xxxx:WaitForChild(“PlayerGui”)’ - Server

The player sees this:

But should see this
image

Could there be a script somehow moving or deleting that instance?

im read it and try this

local PlrGui = player:FindFirstChild(“PlayerGui”)
local Washer = PlrGui.Washers

@CTGTheCreator
that is what I tried but that player still got

08:50:29.243 Infinite yield possible on ‘xxxx:WaitForChild(“PlayerGui”)’ - Server

@x1_EE
If it was due to a script, wouldn’t all players experience the problem? I have a feeling it’s now for a small percentage of players.

hmmm also i want ask in the folder wat value use for?

hmmm also i want ask in the folder wat value use for?

Sorry I don’t understand the question?

ok ik rn u use a bool value for save ui right? well i think dont put it in player gui put it in outside

also ik why rn
in the wait for child u need add wait like this
player:WaitForChild(“PlayerGui”, 1)

What wold the ‘1’ at the end do?

Is it a local script? Clients can not read other player’s player gui folder. It is not replicated to them. As for the error of the player added not always working, add a for loop after the player added just in case a player joins before the script had time to load.

local NewPlayer=function(Player)
if(not(Player:GetAttribute'Loaded'))then
Player:SetAttribute('Loaded',true);
local PG=Player:waitForChild'PlayerGui';
for _,a in next,Game.StarterGui:children() do
a:clone().Parent=PG;
end:
end:
end;
Game.Players.PlayerAdded:connect(NewPlayer);
for _,a in next,Game.Players:players() do
NewPlayer(p);
end;

You can use this in a Script in ServerScriptService.

1 Like

It is the amount of time in seconds before it stops waiting and returns nil. Only if it didn’t find it in the given time.

Good idea, Maybe put a changed event and see if the parent gets moved.

Hi, tnx for the code.
Somehow it gives some errors (as it is)

I’m thinking of creating the folder and StringValues/IntValues using my serversided datastore2 script
As the values are all empty in and loaded from the datastore2 in the next step.
I’ll place the elements a level higher (straight into ‘player’ instead of ‘playergui’.
The only problem… the changes need to be made in all my scripts… (more then 1000 places :confused: )

But I expect/hope this will solve my problem.

	local washers= Instance.new("Folder", player)
	washers.Name = "Washers"

	local washer1= Instance.new("StringValue")
	washer1.Name = "Washer1"
	washer1.Value = Washer1Store:Get("PW8008Washer")
	washer1.Parent = washers

Finished all the changes and published … (and tested it a bit)
Will see tomorrow if I see a lot of errors or get a lot of complains…

The problem is that I have never been able to reproduce the problem myself. But I’ve seen several players who had the issue…
(to be continued)