local players = {game.Players:GetPlayers()}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function(died)
if table.find(players, player) then
table.remove(players, player)
end
end)
end)
end)
print(players)
repeat
wait(1)
StartRound()
until #players == 1
changeColourText(players[1].." has won the game!")
table.clear(players)
table.remove expects an index to remove, you can put the result of table.find(players, player) in a variable, check if it’s not nil and if isn’t nil, use the result to remove from the table
And since you’re using player instance, you can just use players[1].Name to get the name of the player who won
Not sure if anything will be affected byt it but
local players = {game.Players:GetPlayers()}
You don’t need to encase it, GetPlayers() returns a table
local players = {game.Players:GetPlayers()}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function(died)
local find = table.find(players, player)
if find then
table.remove(players, find)
end
end)
end)
end)
print(players)
repeat
wait(1)
StartRound()
until #players == 1
print (players[1].Name)
changeColourText(players[1].Name.." has won the game!")
table.clear(players)
end
Then the table item obviously doesn’t exist.
If that is your script and the local players = game.Players:GetPlayers() isn’t inside a function the it will run when the game starts before the player joins, therefor making the table empty.
That is unneeded if instances are contained in that table, which there are. All @OP needs to do is just get the name from that player via players[1].Name