How can I make gui's update to saved data when the player joins the game?

I’ve made a datastore, it’s working perfectly fine, saves all the data, I have some gui’s on the screen that display some of these values that are being saved, but I can’t figure out how to make it so when the player joins the game, it displays the saved data values instead of the default values. It just changes to the saved values when the values themselves change, for example, when I join the game, my money displayed is 0, but when I sell something, it updates to the saved data. I want to make it so the saved value is displayed when the player joins the game, instead of the default one (0), but I can’t figure out how.

1 Like

Do you mind sending your current script?

1 Like

When a player joins a game, fire the remote that updates the stats for the gui.

There’s no event that updates the gui, it’s just taking the intvalue that it’s displaying and using the “Changed” event (All of this is happening in a local script inside the gui). I tried doing this in serverscript service:

game.Players.PlayerAdded:Connect(function(player)
    	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,7677319) or player.Name == "At0micTac0" then
    		player.PlayerGui:WaitForChild("Main").Gears.GearsAmount.Text = player.Stats.gearsStored.Value.." / ∞"
    	else
    		player.PlayerGui:WaitForChild("Main").Gears.GearsAmount.Text = player.Stats.gearsStored.Value.." / "..player.Stats.gearsCapacity.Value
    	end
    end)

But then the text is just “TextBox”. If it means anything, the value of gearsCapacity is the max an int value can have (2147483647).

You can’t change gui on the server, so you can either set up a remote event and fire it to the client that changes the gui, or just change in the local script

When I change it in the local script it still says “TextBox”
EDIT: Nevermind I didn’t disable the script in serverscriptservice, now it’s just displaying the default value (25) instead of the infinity symbol.

I just added a print after the PlayerAdded event, and it didn’t print :upside_down_face:

PlayerAdded won’t fire for players already in the server when the event is connected.
To fix this, you can cycle through all the players already ingame when the script first starts.

Example:

local function onPlayerAdded(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,7677319) or player.Name == "At0micTac0" then
    	player.PlayerGui:WaitForChild("Main").Gears.GearsAmount.Text = player.Stats.gearsStored.Value.." / ∞"
    else
    	player.PlayerGui:WaitForChild("Main").Gears.GearsAmount.Text = player.Stats.gearsStored.Value.." / "..player.Stats.gearsCapacity.Value
    end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
for _,player in pairs(game.Players:GetPlayers()) do
    onPlayerAdded(player)
end
2 Likes

This fixed the problem, not entirely sure how it works but I’ll try to understand it, thanks!

it works by detecting if the player was added or not in the second part of the script, and that connects to the first part of the script. Then, the first part of the script fires and then it detects if the player has a gamepass with marketplace service. And then the next line is what makes the text appear(I assume you know how that works)