Help displaying leaderstats onto UI

I want my leaderstats info to display on a UI e.g Coins on a CoinsUI and Gems on a GemsUI

Here is the code:

	local leaderstats = player:WaitForChild("leaderstats")
	
	local CoinAmount = script.Parent.SideBar.CoinValue.Amount
	local GemAmount = script.Parent.SideBar.GemValue.Amount
	
	CoinAmount.Text = leaderstats.Coins.Value
	GemAmount.Text = leaderstats.Gems.Value
end)

What is the issues? and can you send the full code?

You should also do this:```

local leaderstats = player:WaitForChild("leaderstats")
	
	local CoinAmount = script.Parent.SideBar.CoinValue.Amount
	local GemAmount = script.Parent.SideBar.GemValue.Amount
	
	CoinAmount.Text = leaderstats.Coins.Value
	GemAmount.Text = leaderstats.Gems.Value

function coinchanged()
CoinAmount.Text = leaderstats.Coins.Value
end)

function gemchanged()
GemAmount.Text = leaderstats.Gem.Value
end)

leaderstats.Coins.Changed:Connect(coinchanged)
leaderstats.Gems.Changed:Connect(gemchanged)
end)

Doesnt work

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")

	local CoinAmount = script.Parent.SideBar.CoinValue.Amount
	local GemAmount = script.Parent.SideBar.GemValue.Amount

	CoinAmount.Text = leaderstats.Coins.Value
	GemAmount.Text = leaderstats.Gems.Value

	local function coinchanged()
		CoinAmount.Text = leaderstats.Coins.Value
	end

	local function gemchanged()
		GemAmount.Text = leaderstats.Gem.Value
	end

	leaderstats.Coins.Changed:Connect(coinchanged)
	leaderstats.Gems.Changed:Connect(gemchanged)
end)

No error

Try using a while() loop.

while wait() do
      CoinAmount.Text = leaderstats.Coins.Value
      GemAmount.Text = leaderstats.Gems.Value
end

Is this a local script?-----------------------------------------

Yes, this is in a local script.

PlayAdded Event does not fire on a local script

Instead reference the player use local plr = game.Players.LocalPlayer

So shall I copy and paste this code into a normal script in server script service

Dont say that! Nobody is stupid

No No. You do not need to.

local player = game.Players.LocalPlayer

	local leaderstats = player:WaitForChild("leaderstats")

	local CoinAmount = script.Parent.SideBar.CoinValue.Amount
	local GemAmount = script.Parent.SideBar.GemValue.Amount

	CoinAmount.Text = leaderstats.Coins.Value
	GemAmount.Text = leaderstats.Gems.Value

	local function coinchanged()
		CoinAmount.Text = leaderstats.Coins.Value
	end

	local function gemchanged()
		GemAmount.Text = leaderstats.Gem.Value
	end

	leaderstats.Coins.Changed:Connect(coinchanged)
	leaderstats.Gems.Changed:Connect(gemchanged)

Why are you ending a non-existant function?

local gemAmount = script.Parent.SideBar.GemValue.Amount
local coinAmount = script.Parent.SideBar.CoinValue.Amount
local player = game.Players.LocalPlayer

local leaderstats = player:WaitForChild("leaderstats")
local gemValue = leaderstats:WaitForChild("Gems")
local coinValue = leaderstats:WaitForChild("Coins")

gemAmount.Text = gemValue.Value
coinAmount.Text = coinValue.Value

gemValue.Changed:Connect(function()
  gemAmount.Text = gemValue.Value
end)

coinValue.Changed:Connect(function()
  coinAmount.Text = coinValue.Value
end)

Is that it?

I’d create references to the individual stats like you have, that way you’re not frequently indexing the leaderstats instance for its “-Value” instances.

local players = game:GetService("Players")
local player = players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local gems = leaderstats:WaitForChild("Gems")
local coins = leaderstats:WaitForChild("Coins")

local frame = script.Parent
local sideBar = frame.SideBar
local gemLabel = sideBar.GemValue
local gemAmount = gemLabel.Amount
local coinLabel = sideBar.CoinValue
local coinAmount = coinLabel.Amount

gemAmount.Text = gems.Value
coinAmount.Text = coins.Value

gems.Changed:Connect(function(newGems)
	gemAmount.Text = newGems
end)

coins.Changed:Connect(function(newCoins)
	coinAmount.Text = newCoins
end)