Last three players in a table?

I want to make a table with the last three players in a round. Once a player dies it will update the table and change the positions of the usernames according to what place they placed in for example:

I have {John, Joe, Frawn} in a table. John dies so he should move to third place and Joe and Frawn move up 1 in the table it should look like this now {Joe, Frawn, John}.
Let’s say Joe dies next Frawn is the winner Joe is second and John is last looks like this {Frawn, Joe, John}

Thank you anything will help :slight_smile:

Get the last index of the table and iterate backwards.

local Names = {‘Ken’, ‘Sarah’, ‘John’, ‘Lee’};
local Len = table.len(Names)
local L1, L2, L3 = Names[Len], Names[Len - 1], Names[Len - 2];
local podiumPlayers = {}
local playersLeft = {1, 2, 3} --Example values.
--If 3 dies then.
table.insert(podiumPlayers, 3)
--If 2 dies then.
table.insert(podiumPlayers, 2)
--1 player remaining.
table.insert(podiumPlayers, 1)
for i = #podiumPlayers, 1 -1 do
	print(podiumPlayers, i)
end

Essentially what you’d do is play the round as normal & wait for three players to be remaining at which point if any player dies they will be inserted into the “podiumPlayers” array, once the round ends this array can be iterated over backwards to get the positions of the top three players.