How would I make a 'Your the richest person' Gui

My game is a tycoon and I want to make a gui. Every minute it would say who the richest person on the server is and how much cash they have. Keep in mind that I am new at programming and very new at using gui’s. I hope we can figure this out together!

My cash is called cash in the script.

Here:

local playersCashes = game:GetService("ReplicatedStorage"):WaitForChild("playerCashes") -- Put path to playersCashes here
local playerCashesTable = {} -- Will use table.sort later to display highest

game.Players.PlayerAdded:Connect(function(player)
	table.insert(playerCashesTable, player:WaitForChild("Cash").Value)
	
	local playerCash = Instance.new("StringValue", playersCashes)
	playerCash.Name = player:WaitForChild("Cash").Value -- This is to get the player name
	playerCash.Value = player.Name -- The player cash path
end)

while task.wait(1) do
	-- Sort table greatest to least
	table.sort(playerCashesTable, function(cash1, cash2)
		return cash1 > cash2
	end)
	
	local richestPlayerCash = playerCashesTable[1]
	local richestPlayerName = playersCashes:WaitForChild(richestPlayerCash).Value
	
	for _, player in ipairs(game.Players:GetChildren()) do
		local playerGui = player:WaitForChild("PlayerGui")
		local cashTextLabel = playerGui:WaitForChild("PathTextLabel") -- Path to text label here
		
		cashTextLabel = richestPlayerName.. " has ".. richestPlayerCash.. " cash!"
	end
end
1 Like

would i just put this in a script in server script service?

Yes you would put this in a script in serverscript service (be sure it is a new script)

And you would also replace the variable with your path to some of the things

ok i will try it thanks. I hope it works

Nothing changed how would I see if it worked?

Can you share the script?

char limit

What? I dont get it. What does that mean

Like copy paste the code here so I can see what you are doing

local playersCashes = game:GetService(“ReplicatedStorage”):WaitForChild(“playerCashes”) – Put path to playersCashes here
local playerCashesTable = {} – Will use table.sort later to display highest

game.Players.PlayerAdded:Connect(function(player)
table.insert(playerCashesTable, player:WaitForChild(“Cash”).Value)

local playerCash = Instance.new("StringValue", playersCashes)
playerCash.Name = player:WaitForChild("Cash").Value -- This is to get the player name
playerCash.Value = player.Name -- The player cash path

end)

while task.wait(1) do
– Sort table greatest to least
table.sort(playerCashesTable, function(cash1, cash2)
return cash1 > cash2
end)

local richestPlayerCash = playerCashesTable[1]
local richestPlayerName = playersCashes:WaitForChild(richestPlayerCash).Value

for _, player in ipairs(game.Players:GetChildren()) do
	local playerGui = player:WaitForChild("PlayerGui")
	local cashTextLabel = playerGui:WaitForChild("PathTextLabel") -- Path to text label here

	cashTextLabel = richestPlayerName.. " has ".. richestPlayerCash.. " cash!"
end

end

I just copied and pasted your code into server script service

I just copied your code and pasted it

You have to change the path to some variables for it to work…

like what i told you in a beginer what isa path?

do a for loop for everyone in the server and the person with the most cash will be set as the richest

So for the variables playerCashes and cashTextLabel, you have to change it so the they are equal to where those things are located.

-- This is a path
game:GetService("ReplicatedStorage"):WaitForChild("Test")

Since you don’t have some objects in the script I gave you in your actual game you will have to replace the variable’s values so they equal the object in the game.

Some things to keep out for

First of all you will need to add the cash int value into the player when they join, I gave a script in the end that does this for you

Also when you are changing the value’s of your variables that I told you to change to your object’s path be sure that for the playerCashes variable the parent of the object is replicated storage, and for castTextLabel is StarterGui.

Also you want to insert a gui in starter gui and then a frame in the gui, then you want to insert a textlabel inside the frame.

Here is the update script just change the values which I told you to change with the object’s paths:

local playersCashes = game:GetService("ReplicatedStorage"):WaitForChild("playerCashes") -- Put path to playersCashes here
local playerCashesTable = {} -- Will use table.sort later to display highest

game.Players.PlayerAdded:Connect(function(player)
local cash = Instance.new("IntValue", player)
cash.Name = "Cash"
cash.Value = math.random(1, 10000) -- You have to change this when you are adding cash to the player

	table.insert(playerCashesTable, cash.Value)
	
	local playerCash = Instance.new("StringValue", playersCashes)
	playerCash.Name = cash.Value -- This is to get the player name
	playerCash.Value = player.Name -- The player cash path
end)

while task.wait(1) do
	-- Sort table greatest to least
	table.sort(playerCashesTable, function(cash1, cash2)
		return cash1 > cash2
	end)
	
	local richestPlayerCash = playerCashesTable[1]
	local richestPlayerName = playersCashes:WaitForChild(richestPlayerCash).Value
	
	for _, player in ipairs(game.Players:GetChildren()) do
		local playerGui = player:WaitForChild("PlayerGui")
		local cashTextLabel = playerGui:WaitForChild("PathGui"):WaitForChild("PathFrame"):WaitForChild("PathTextLabel") -- Path to screenGui and then frame and then text label here
		
		cashTextLabel = richestPlayerName.. " has ".. richestPlayerCash.. " cash!"
	end
end

What does the objects path mean?

like if there is an object in the explorer, let’s say “testPart” and it’s parent is ReplicatedStorage.

So to access it, you would have to do:

game:GetService("ReplicatedStorage"):WaitForChild("testPart")

This is the path, basically the location of the object in the explorer written in code

So you need to change the path of the variables I told you to change to where you have the objects. But keep in mind that those object’s parents should be what I told you.

2 Likes

i am very confused. Can i just have the completed code?

RichestPlayer.rbxl (41.9 KB)

Here you go, just change it to your liking gui wise.