Most coins collected

Hello everyone, currently i am making a murder mystery game and at the end of the round it will tell players who collected the most coins but i don’t know how i can achieve this, any help?

i was not asking for a full script but ok

1 Like

If you want to know more information (or you didn’t understand) please reply

You could do something like this:

  • Make a intvalue in the player, possibly named, “CollectedCoins”

  • Round Starts

  • Player Collects Coin

  • After they collect it, add 1 point to a value inside of the player.

  • This part can go 2 ways:

  • Player dies, you can set the value to zero, and/or reward them their collected coins

  • Or, round ends: loop through the players and calculate who collected the most, and then reward the players their coins and set the collected coins value to 0.
    (I’m not sure what math you’d have to do figure out something.)

This should point you in the right direction.
There are many other ways to go about this.

For the math you could just have a default Highest value before the loop, (set to 0.)

Then while you loop just check if the player’s coins are greater then the Highest value, if yes then set the Highest value to player’s coin value and the player along with it, in some other variable hopefully.

1 Like

Hello there, @Chai_rbf

The user posting this thread did not ask for a full script. He was asking how he can find which player has the most coins. Please read the post. You can find it here.

I hope this helped!

3 Likes

I Don’t understand, is there a example of how to do this?

Example

local t = {player1 = 4, player2 = 3, player3 = 7, player4 = 6, player5 = 1, player6 = 0}
--player1~6 = username
--value = collected coins

local key = next(t)
local max = t[key]

for k, v in pairs(t) do
    if t[k] > max then
        key, max = k, v
    end
end

print(key, max) --Print player3 7