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

How do I get this script to update my custom leaderboard to work?

Asked by 8 years ago
Edited 8 years ago

I created a custom leaderboard for my game, but the problem is that the textlabel will not update the text based on the money of the other players. The script is a local script inside of the GUI.

01local REP           =       game.ReplicatedStorage
02local PLAYER        =       game.Players.LocalPlayer
03 
04repeat wait() until PLAYER:FindFirstChild("PlayerGui")
05 
06local FRAME         =       script.Parent:WaitForChild("ScrollingFrame",3)
07local FC                =       FRAME:GetChildren()
08 
09while wait() do
10    for i,v in pairs(game.Players:GetPlayers()) do
11        print(v.Name.." has "..REP.PlayerValues:WaitForChild(v.Name,2).GameValues.TotalMoney.Value.." money.") -- This does correctly print their money
12        print(FC[i].Text) -- This does print the name of the player
13        if FC[i].Text == tostring(v) then -- Error most likely has to do with this
14            FC[i].TextLabel.Text = "$"..REP.PlayerValues[v.Name].GameValues.TotalMoney.Value
15            -- Nothing ever happens with this. It is meant to be a textlabel inside of another textlabel and that is not the problem.
16        end
17    end
18end
0
Check to see if the object WaitForChild is looking for has actually been found, because it stops your code until it has found said object. Also look at your output, as it shows errors in your code. TheDeadlyPanther 2460 — 8y
0
I edited the script to account for that. It still only updates the money value for the current person, not any others in the game. The output doesn't show any errors. RockerCaleb1234 282 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Your problem is in line 13. You are trying to call tostring on an object

v in i,v is the player in Players. I think you are trying to call v.Name

Revised script:

01local REP           =       game.ReplicatedStorage
02local PLAYER        =       game.Players.LocalPlayer
03 
04repeat wait() until PLAYER:FindFirstChild("PlayerGui")
05 
06local FRAME         =       script.Parent:WaitForChild("ScrollingFrame")
07local FC                =       FRAME:GetChildren()
08 
09while wait() do
10    for i,v in pairs(game.Players:GetPlayers()) do
11        print(v.Name.." has "..REP.PlayerValues:WaitForChild(v.Name).GameValues.TotalMoney.Value.." money.") -- This does correctly print their money
12        print(FC[i].Text) -- This does print the name of the player
13        if FC[i].Text == tostring(v.Name) then -- Error most likely has to do with this
14            FC[i].TextLabel.Text = "$"..REP.PlayerValues[v.Name].GameValues.TotalMoney.Value
15            -- Nothing ever happens with this. It is meant to be a textlabel inside of another textlabel and that is not the problem.
16        end
17    end
18end
0
tostring(v.Name) seems a bit redundant... EzraNehemiah_TF2 3552 — 8y
0
tostring(object) returns the object's name, although object.Name can be more fool proof (in turns of what it returns, not errors) TheDeadlyPanther 2460 — 8y
0
Yet, I still don't know why the script doesn't work. RockerCaleb1234 282 — 8y
Ad

Answer this question