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.
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.
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.
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 )
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