Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to display leaderstats in a Gui?

Why does this not work?

local user = game.Players.LocalPlayer
local stats = user:findFirstChild("leaderstats")

while true do
script.Parent.Text = "" .. user.leaderstats.Coins.Value ..""
wait(0.1)
end

Error: Script 'Players.Player.PlayerGui.Leaderboard Tires.Leaderboard.Coin.Display', Line 4 and leaderstats is not a valid member of Player

2 comments

0

I see you're using LocalPlayer, is it in a LocalScript?

0

Noo, but its Solved

1 answer

✓ Accepted answer

Use WaitForChild. It will delay until it finds the required object. Also, you do not need those set of quotes around the string.

Also, use events rather than a loop. It's much more efficient.

local user = game.Players.LocalPlayer
local stats = user:WaitForChild("leaderstats")
local coins = stats:WaitForChild("Coins")

function update()
script.Parent.Text = coins.Value
end

coins.Changed:connect(update)

1 comment

1

Thanks you devChris now i learned some more stuff today!

This discussion is preserved as it was. New answers, comments, and votes are closed.