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!
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
local playersCashes = game:GetService(“ReplicatedStorage”):WaitForChild(“playerCashes”) – Put path to playersCashes here
local playerCashesTable = {} – Will use table.sort later to display highest
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
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
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.