Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to display leaderstats in a Gui?

Asked by 8 years ago

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

0
I see you're using LocalPlayer, is it in a LocalScript? iFlusters 355 — 8y
0
Noo, but its Solved minetrackmania 186 — 8y

1 answer

Log in to vote
2
Answered by
DevChris 235 Moderation Voter
8 years ago

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
Thanks you devChris now i learned some more stuff today! minetrackmania 186 — 8y
Ad

Answer this question