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

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

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.

local REP 			=		game.ReplicatedStorage
local PLAYER		=		game.Players.LocalPlayer

repeat wait() until PLAYER:FindFirstChild("PlayerGui")

local FRAME			=		script.Parent:WaitForChild("ScrollingFrame",3)
local FC				=		FRAME:GetChildren()

while wait() do
	for i,v in pairs(game.Players:GetPlayers()) do
		print(v.Name.." has "..REP.PlayerValues:WaitForChild(v.Name,2).GameValues.TotalMoney.Value.." money.") -- This does correctly print their money
		print(FC[i].Text) -- This does print the name of the player
		if FC[i].Text == tostring(v) then -- Error most likely has to do with this
			FC[i].TextLabel.Text = "$"..REP.PlayerValues[v.Name].GameValues.TotalMoney.Value 
			-- Nothing ever happens with this. It is meant to be a textlabel inside of another textlabel and that is not the problem.
		end
	end
end

2 comments

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.

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.

1 answer

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:

local REP           =       game.ReplicatedStorage
local PLAYER        =       game.Players.LocalPlayer

repeat wait() until PLAYER:FindFirstChild("PlayerGui")

local FRAME         =       script.Parent:WaitForChild("ScrollingFrame")
local FC                =       FRAME:GetChildren()

while wait() do
    for i,v in pairs(game.Players:GetPlayers()) do
        print(v.Name.." has "..REP.PlayerValues:WaitForChild(v.Name).GameValues.TotalMoney.Value.." money.") -- This does correctly print their money
        print(FC[i].Text) -- This does print the name of the player
        if FC[i].Text == tostring(v.Name) then -- Error most likely has to do with this
            FC[i].TextLabel.Text = "$"..REP.PlayerValues[v.Name].GameValues.TotalMoney.Value 
            -- Nothing ever happens with this. It is meant to be a textlabel inside of another textlabel and that is not the problem.
        end
    end
end

3 comments

0

tostring(v.Name) seems a bit redundant...

0

tostring(object) returns the object's name, although object.Name can be more fool proof (in turns of what it returns, not errors)

0

Yet, I still don't know why the script doesn't work.

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