Why when I rejoin my GUI for leaderstats do not show

Hello! I am having an issue where when I have an amount of money, and rejoin, it does not show. In Roblox Studio it does not do this. How can I fix this? Here is also what my problem is in a video.

What it does in studio - 2021-10-09 13-33-54

Here is my script for the Money GUI, and Gem GUI. The Coin GUI Does not do this because it is using a different script.


function Comma(amount)
	while true do
		amount, k = string.gsub(amount, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k == 0) then
			break
		end
	end
	return amount
end

Players.LocalPlayer.leaderstats.Gems:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = " "..Comma(Players.LocalPlayer.leaderstats.Gems.Value)
end)

Try setting the Text as the script is ran.

local function Display()
	script.Parent.Text = " "..Comma(Players.LocalPlayer.leaderstats.Gems.Value)
end

Display()
Players.LocalPlayer.leaderstats.Gems:GetPropertyChangedSignal("Value"):Connect(Display)

Also did you try pressing F9 and checking dev console to see if there was any errors?

Maybe the player’s leaderstats instance doesn’t exist the moment the script is ran, so maybe you could try adding :WaitForChild

local Players = game:GetService("Players")

local Client = Players.LocalPlayer
local Leaderstats = Client:WaitForChild("Leaderstats")
local Gems = Leaderstats:WaitForChil("Gems")

local function Display()
	script.Parent.Text = " "..Comma(Gems.Value)
end

Display()
Gems:GetPropertyChangedSignal("Value"):Connect(Display)

Do you save your data in some time of database or the roblox data storage?

It will not save between servers if not I believe anyways.

Like this?

Here is my Datastore Script for Leaderstats.

game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.Coins
	local save2 = plr.leaderstats.Money
	local save3 = plr.leaderstats.Gems
	local save4 = plr.leaderstats.EggsOpened
	
	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
		save3.Value = GetSaved[3]
		save4.Value = GetSaved[4]
	else
		local NumberforSaving = {save1.Value, save2.Value, save3.Value, save4.Value}
		ds:GetAsync(plrkey, NumberforSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Coins.Value, plr.leaderstats.Money.Value, plr.leaderstats.Gems.Value, plr.leaderstats.EggsOpened.Value})
end)

Gems.Changed would also work here

1 Like

I had no idea! I assumed since it was an Instance that it should behave like any other .Changed signal.

Cool to know.

No, no errors show up. Also you did a error in the Script, you forgot to put a d in Child.


I get that error when I use your script.


I am getting an error when I use your script.

  13:48:21.726  Stack Begin  -  Studio
  13:48:21.726  Script 'Players.Annexsohn.PlayerGui.Gem Leaderstat.TextLabel.LocalScript', Line 4  -  Studio - LocalScript:4
  13:48:21.726  Stack End  -  Studio

try put this:

local pl_s1 = game:GetService("Players")
local function Player(tp_t1)
	local a1 = Instance.new("Folder", tp_t1)
	a1.Name = "Leaderstats"
end
pl_s1.PlayerAdded:Connect(Player)