Hello so what I'm trying to do here is on line 32 I'm removing the player UserId From the table but when the players is removed (Which is not getting removed) it's showing after 3 seconds in the output that there's still 2 players and the "Winner" is Player1 but Player2 is still in the map and Player1 is in the lobby, and the table named "playeringame" is saying the the first value of the table is Player1. And also on line 26 I'm adding the player to the "playeringame"
Here's the code:
local playeringame = {} local Status = game.ReplicatedStorage:WaitForChild("Status") Status.Value = "Waiting For Players..." game.Players.PlayerAdded:Connect(function(player) repeat wait() until #game:GetService("Players"):GetPlayers() >= 1 wait(2) for i = 4, 1, -1 do Status.Value = "Staring Game in "..i wait(1) end Status.Value = "Loading Map..." local ClonedMap = game.ReplicatedStorage.Maps.Map01:Clone() ClonedMap.Parent = workspace ClonedMap.Name = "Map" wait(2) game.ReplicatedStorage.NumbersPlayersInGame.Value = #game:GetService("Players"):GetPlayers() table.insert(playeringame, player.UserId) player.Character.HumanoidRootPart.CFrame = workspace:WaitForChild("Map").Spawns.Spawn.CFrame player.Character.Humanoid.Died:Connect(function() game.ReplicatedStorage.NumbersPlayersInGame.Value -= 1 table.remove(playeringame, player.UserId) end) repeat wait() until game.ReplicatedStorage.NumbersPlayersInGame.Value == 1 if game.ReplicatedStorage.NumbersPlayersInGame.Value == 1 then Status.Value = "Game Ended" game.ReplicatedStorage.NumbersPlayersInGame.Value = 0 game.ReplicatedStorage.LastPlayer.Value = playeringame[1] wait(3) --print(game.Players:GetPlayerByUserId(playeringame[1]).Name) print(#playeringame) end end)
Also here' the output I put it in a image and here's the image https://i.postimg.cc/ZRRFWvDB/a7.png
table.remove
removes the index value of the table you set in the second parameter, and you can't actually remove it by using the player's user ID.
you can find the index of the value you are looking for by using table.find
try replacing line 32 with this:
table.remove(playeringame, table.find(playeringame, player.UserId))