Stat Label not working

LocalScript

local player = game.Players.LocalPlayer
player.PlayerGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value

player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
end)
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value
end)

This shows the value 0 until the value is changed. Anyone got ideas?

This is in a LocalScript, correct?

Don’t use

player.PlayerGui

Define the GUI Elements through a localscript in the gui instead of using playerGui to find them.

1 Like

local script

local player = game.Players.LocalPlayer

game.StarterGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
game.StarterGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value

player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
	game.StarterGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
end)
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	game.StarterGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value
end)

now they arent changing at all

Would you mind sending me your place file?

You don’t want to access the stats from “game.StarterGui”

You want to access them directly from the GUI you’re changing and you’ll want to have your LocalScript inside of that gui.

You are using game.StarterGui, the startergui replicates to everyone in the form of player gui,

Basically all you have to do is change game.StarterGui to script.Parent depending on where your script is placed… Or I am unsure if this will work but try doing player.PlayerGui from the localscript.

1 Like

First, changing StarterGui wouldn’t change anything in a local script. You would define it through either PlayerGui or by finding the objects in relation to the script’s location (recommended)

Second, where is your localscript in relation to the textlabels?

Third, have you tried adding using WaitForChild() on leaderstats in your original code?

You don’t need those two lines. Also you you can get rid of “game.startergui” and index the texlabel using script.Parent.

He uses those lines to define the value right when the player joins, as the getpropertychangedsignal wouldn’t activate until after the initial values have been set.

Really? I’m pretty sure it works fine without defining the values at first (I mean the value shoudn’t be nil) Also like you said he should probably use WaitForChild on leaderstats.

Edit: I just realised I’m wrong lol. It’s probably best to define the values at first, as you don’t want your GetPropertyChangedSignal to be erroring.

It’s because your script runs it before the player even enters the game. Do this instead


repeat wait() until player.Character or player.CharacterAdded

player.PlayerGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value

player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
end)
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value
end)

Try putting them in a while loop like this so it checks the coint every seond

while wait(1) do
local player = game.Players.LocalPlayer

game.StarterGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
game.StarterGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value

player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
	game.StarterGui.Stats.Coins.TextLabel.Text = player.leaderstats:WaitForChild("Coins").Value
end)
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	game.StarterGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value
end)
end