I need to find the player with the most money on the server and I want to show the player with the most money with a TextLabel.
Example:
I would be happy if you could help for this.
I need to find the player with the most money on the server and I want to show the player with the most money with a TextLabel.
Example:
I would be happy if you could help for this.
Money as in Robux or some type of in-game currency?
If it’s the latter, get every player in a table, then sort the table.
local players = game.Players:GetPlayers()
table.sort(players, function(playerA, playerB)
return playerA.Money.Value > playerB.Money.Value
end)
local RichestPlayer = players[1]
print(RichestPlayer.Name.." is the richest player!")
Not Robux. I need to find the person who has the most money in the game and I want to show the person with the most money with a text label.
If you are using leaderstats,
local players = game.Players:GetPlayers()
local function GetCurrencySortedList(list)
return table.sort(list, function(a, b)
return a.leaderstats.Money.Value > b.leaderstats.Money.Value
end)
end
local function Update()
local playerHighest = GetCurrencySortedList(players)[1]
script.Parent.TextLabel.Text = ("%s is the richest player with $%s"):format(playerHighest.Name, playerHighest.leaderstats.Money.Value) --Second third and so on by changing the index
end
Update()
I need something like this.I tried the script you suggested but it didn’t work.
I edited my previous reply, please provide your explorer view too.
I think there was a problem due to differences in my leaderstats.Thanks for your help!But did’nt work.
Can you please provide the explorer view of the leaderstats?
If someone has given a script in devforum, think how you can learn from it and then implement it for your game, don’t just copy paste.
As for your game, you probably need to change the references, then it should work.
This:
function onPlayerEntered(newPlayer)
wait()
local Leaderstats = Instance.new(“IntValue”)
Leaderstats.Name = “leaderstats”local currency = Instance.new(“IntValue”)
currency.Name = “Money”
currency.Value = 0currency.Parent = Leaderstats
Leaderstats.Parent = newPlayer
endgame.Players.ChildAdded:connect(onPlayerEntered)
Where is your script and textlabel in relation to each other?
You can use HighestNum variable, and then check if the current player you are looping through has a higher amount of X than the value itself, if so, change the value:
local players = game:GetService("Players");
local highestValue, playerName = 0, nil;
for _, v in ipairs(players) do
if v.leaderstats.Cash.Value > highestValue then -- Edit that to fit to your game.
highestValue = v.leaderstats.Cash.Value
playerName = v.Name
end
end
print(playerName.. " has the highest amount of cash with ".. highestValue)
Sorry I mistyped the script. It works now.