# 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

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.

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}