Winner Script System Only Works With One Player in the Server?

I have a winner script in my game, if someone wins, it announces it at the end of the round.

Right now it only works with one person in the game for some reason.

So far, I tried looking on the Developer Hub for solutions, and found something to make this script possible, but it still only works with one person in the server.

`local round_players = {}

local maps = require(game.ServerScriptService.Maps)
local x = 0

while true do
wait(0)
for i, v in pairs(maps) do
if game.Workspace.MapStorage:FindFirstChild(v) then
local round_players = {}
for i, player in pairs(game.Players:GetPlayers()) do
table.insert(round_players, player)
repeat
wait(0)
x = x+1
print(x)
player.Character.Humanoid.Died:Connect(function()
print(player.Name … " has died!")
table.remove(round_players, i)
end)
until x == 1350
x = 0

			for i, player in pairs(game.Players:GetPlayers()) do
			local msg = ""
			for i, player in pairs(round_players) do
			if player and player.Parent then
			msg = msg.."Winners: "..player.Name
			end
			end
			msg = msg..""
			player.PlayerGui.MapNameGui.TextLabel.Text = msg	
			end
		end
	end
end

end`

I’m very sorry if this script is confusing. Thank you for reading! :slight_smile:

Edit: Sorry the script formatted weird. I don’t know why it did that.

local round_players = {}


local maps = require(game.ServerScriptService.Maps)
local x = 0

while true do
wait(0)
for i, v in pairs(maps) do
if game.Workspace.MapStorage:FindFirstChild(v) then
local round_players = {}
for i, player in pairs(game.Players:GetPlayers()) do
table.insert(round_players, player)
repeat
wait(0)
x = x+1
print(x)
player.Character.Humanoid.Died:Connect(function()
print(player.Name … " has died!")
table.remove(round_players, i)
end)
until x == 1350
x = 0

			for i, player in pairs(game.Players:GetPlayers()) do
			local msg = ""
			for i, player in pairs(round_players) do
			if player and player.Parent then
			msg = msg.."Winners: "..player.Name
			end
			end
			msg = msg..""
			player.PlayerGui.MapNameGui.TextLabel.Text = msg	
			end
		end
	end
end
end

Here is the script with the code block formatted correctly! :slight_smile:

1 Like

I can’t really see what this is even trying to do. Why are you connecting 1350 different functions to each player’s Died event?

1 Like

That part checks if any player has died and if I make the wait longer than Wait() it won’t work very well. I put it as 1350 because it’s about 45 seconds with waits in between. Tthank you for responding! :slight_smile:

I can’t even read this please ident your script so that we can read it.

1 Like

Also wouldn’t your script do something like:
Winners: playername Winners: playername2 Winners: playername3
since you just append Winners: + name each time? Is that intended?

1 Like

It wouldn’t let me indent it for some reason, so here’s an image of the script.

If I put more than one person in the server, it only says one person won no matter what.

Is the issue that the table doesn’t have the right players in it or is the issue with the for loop in the end.

1 Like

I believe the issue is that the table doesn’t have the right players.

You should check that, also is the fact that the loop will loop through all the players that are in round_players for each player resulting in a lot of looping, it would be better if you put the round_players loop and then just update everyone’s TextLabel at once afterwards.

1 Like
  1. Don’t use the repeat loop. (hence, no need for x variable)
  2. Add a wait(number) after the (line 10) for loop ends.
  3. You’re connecting .Died 1350 times. (because of the repeat loop)
  4. You never disconnect .Died
  5. Players who leave the game have not been removed from the round_players array.
  6. The (line 24) for loop should be outside of the (line 10) for loop and can be replaced with:
wait(45) --or whatever u want 
			
			for i, player in pairs(game.Players:GetPlayers()) do --Move this out of the for loop on line 10
				local winners = table.concat(round_players,", ")
				player.PlayerGui.MapNameGui.TextLabel.Text = "Winners: "..winners	--i suggest using remoteEvents
			end
  1. Oh, wait() also works fine, wait(0) is unnecessary.
3 Likes