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

Help with my script not sowing their leaderstats?

Asked by 9 years ago

This script is in a text label and is supposed to show the player his Money from the leaderboard. But this script does not work and the output isn't putting up errors. Please help

01game.Players.PlayerAdded:connect(function(player)
02    wait(1)
03    player:WaitForDataReady()
04    repeat wait() until player:FindFirstChild("leaderstats")
05    if player.DataReady then
06        if player:findFirstChild("leaderstats") then
07            local Money = player.leaderstats.Money
08            script.Parent.Text = Money
09        end
10    end
11end)

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
9 years ago

I see what you are trying to do, but you do not need all those checks and waits.

You need to define the Player and Leaderstats:

1local TextLabel = script.Parent
2local Player = TextLabel.Parent.Parent.Parent.Parent
3local Stats = Player:WaitForChild('leaderstats')

Second, you need to create a change event and function:

1Stats:WaitForChild('Money')Changed:connect(function()
2 
3end)

Third step is to code the change:

1TextLabel.Text = stats.Money.Value

Last thing, is to put that all together:

1local TextLabel = script.Parent
2local Player = TextLabel.Parent.Parent.Parent.Parent
3local Stats = Player:WaitForChild('leaderstats')
4 
5Stats:WaitForChild('Money')Changed:connect(function()
6TextLabel.Text = stats.Money.Value
7end)
Ad

Answer this question