First, I would create the turn order in the start of the game, by adding each player that will play into a dictionary, I would also have a variable which says the CurrentTurn.
local TurnOrder = {}
local CurrentTurn = 1
function AddPlayers()
for i,name in pairs(game.Players:GetPlayers()) do
TurnOrder[i] = name
end
end
By doing that the TurnOrder would be something like this:
TurnOrder[1] = Isaque232
TurnOrder[2] = killerdolophin2000
TurnOrder[3] = bobthepants123
After that, on the starting of the game I would check if CurrentTurn exists on the TurnOrder dictionary, which prevents the game from infinitely continue Itâs turns even when they donât have any players on them.
If CurrentTurn does not exist on the dictionary I would set it back up to 1, which basically resets and goes to the starting player.
To get the Player I would simply do: local Player = TurnOrder[CurrentTurn] which would return the value, which would be the player, with this I would be free to do anything to the player!
At the end of the turn I would simply add +1 to the dictionary so it goes to the next player in TurnOrder, and loop the whole thing so the game would keep going.
The script would be basically this:
local TurnOrder = {}
local CurrentTurn = 1
function AddPlayers()
for i,name in pairs(game.Players:GetPlayers()) do
TurnOrder[i] = name
end
end
function StartTurn()
if not TurnOrder[CurrentTurn] then
CurrentTurn = 1
end
local Player = TurnOrder[CurrentTurn])
--Do something to the player here!
CurrentTurn += 1
StartTurn() -- Starts the turn again!
end
AddPlayers() -- Add players to TurnOrder
StartTurn() -- Start the game!
This is just the idea of turns Iâve made up, of course youâre gonna need to change it, so it suits your game.
Hopefully this helps!