So I have this script that runs through all of the players in a table and teleports them to a part. However the last player never spawns at the part and just spawns at the main spawn point (the default spawn point that everyone spawn at when they join the game).
local function teleportPlayersToGame()
local number = 1
local SpawnPoints = ClonedArena:FindFirstChild("SpawnPoints")
repeat
print(#plrs)
local player = plrs[math.random(1,#plrs)]
for x, plr in pairs(plrs) do
if plr == player then
table.remove(plrs,x)
end
end
if number == 1 then
number = number + 1
if player then
character = player.Character
if character then
character.HumanoidRootPart.CFrame = SpawnPoints.SpawnPoint1.CFrame
print("moved to spawn point")
player.playerAmount.Value = 0
game.ReplicatedStorage.WaitScreenEndBang:FireClient(player)
print("remote fired to player")
end
end
elseif number == 2 then
number = number + 1
if player then
character = player.Character
if character then
character.HumanoidRootPart.CFrame = SpawnPoints.SpawnPoint1.CFrame
print("moved to spawn point")
player.playerAmount.Value = 0
game.ReplicatedStorage.WaitScreenEndBang:FireClient(player)
print("remote fired to player")
end
end
elseif number == 3 then
number = number + 1
if player then
character = player.Character
if character then
character.HumanoidRootPart.CFrame = SpawnPoints.SpawnPoint1.CFrame
print("moved to spawn point")
player.playerAmount.Value = 0
game.ReplicatedStorage.WaitScreenEndBang:FireClient(player)
print("remote fired to player")
end
end
elseif number == 4 then
number = number + 1
if player then
character = player.Character
if character then
character.HumanoidRootPart.CFrame = SpawnPoints.SpawnPoint1.CFrame
print("moved to spawn point")
player.playerAmount.Value = 0
game.ReplicatedStorage.WaitScreenEndBang:FireClient(player)
print("remote fired to player")
end
end
elseif number == 5 then
number = number + 1
if player then
character = player.Character
if character then
character.HumanoidRootPart.CFrame = SpawnPoints.SpawnPoint1.CFrame
print("moved to spawn point")
player.playerAmount.Value = 0
game.ReplicatedStorage.WaitScreenEndBang:FireClient(player)
print("remote fired to player")
end
end
end
until #plrs == 0
end
teleportPlayersToGame()