Having trouble making a Winner and Losing System (need help in last reply)

Hello, so I made a intermission system following a tutorial and I would like to integrate a winner system in my script where when the last timer reach 0 (wave) all the remaining players alive (who survived the zombie wave) wins and the list of all the players who won appears. (announcement) and if no one survives it just shows “lost”

The problem is I have no clue how to make it

I want on many Dev forum but I couldn’t find any solution that could help me much…
The only thing I found was a similar post with someone having a similar problem (Can't Figure Out How to Make a Winner System) but when I tried to integrate the solution script in mine it didn’t seem to work (here is the code)

	for i, player in pairs(game.Players:GetPlayers()) do 
		local winners = table.concat(playersInRound,", ")
		player.PlayerGui.MapNameGui.TextLabel.Text = "Winners: "..winners	
	end

(I had a similar concept idea from Survive the Night but maybe Gui version)
Thank You for taking the time to read!

Here is my Intermission system code:

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')

while true do

	--Intermission

	local Countdown = 20 -- intermission

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0

	--Choose the map.

	Status.Value = 'Game Starting'

	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]

	wait(3) -- little pause, make this as long as you want

	ChosenMap.Parent = workspace
	Status.Value = 'Teleporting players.'

	wait(3) -- little pause
	--teleport the players

	local playersInRound = {} -- track alive players
	local connections = {} -- store connections to disconnect later
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
		

			table.insert(playersInRound, Player) -- add all players to table
			connections[Player.Name] = Player.Character.Humanoid.Died:Connect(function() -- remove player from list on death
				table.remove(playersInRound, table.find(playersInRound, Player))
			end)
		end
	end
	
	connections["Removing"] = game.Players.PlayerRemoving:Connect(function(player) -- remove player from list if they leave
		local ind = table.find(playersInRound, player)
		if ind then
			table.remove(playersInRound, ind)
		end
	end)
	

	Countdown = 15 -- Starting Round In

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Starting Round in: '..Countdown
	until Countdown <= 0

	Countdown = 15 -- Wave Round

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Survive the Zombies: '..Countdown
	until Countdown <= 0 or #playersInRound == 0
	
	Status.Value = 'Door Open'

	Countdown = 15 -- Wave intermission
	
	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Next Wave In'..Countdown
	until Countdown <= 0 or #playersInRound == 0
	
	
	--Kill the players
	for _, connection in pairs(connections) do -- disconnect connections to prevent memory leaks
		connection:Disconnect()
	end

	for _, Player in pairs(playersInRound)do
		Player:LoadCharacter()
	end

	ChosenMap:Destroy()

	Status.Value = 'Round Ended, waiting for new game.'
	wait(4) -- little pause

end



There are a number of changes to do.

for i, player in pairs(game.Players:GetPlayers()) do -- delete this
	local winners = table.concat(playersInRound,", ")
	player.PlayerGui.MapNameGui.TextLabel.Text = "Winners: " .. winners -- change this
end -- and this

It’s a one-liner, how fun.

Status.Value = "Winners: " .. table.concat(playersInRound, ", ")

Unless you have a specific GUI that should display winners on the clients. You should do FireAllClients with a remote that contains this string to display that.

2 Likes

Thanks it worked!

also question if i want the game to print “No one Survived, Game Over” when all the player dies should i put the replicate winning code and where should i put it? As i tried putting it on line 44 with some changes (the line that end the game when all player dies) but it doesn’t seem to work.

Do a conditional, that ensures that the table isn’t empty. If it’s empty, just display exactly that string. No concatenations needed.

1 Like

I was unable to make just the losing string work and with a conditional, so i changed the code a bit to merge both the Winning string and the losing string with a conditional. But now when the player dies nothing appears but when the player survive the full round the losing string “Game Over” shows instead of the winning one.
Could someone help me fix the code?

Here is the code:

local msg = ""
	local msg2 = ""
	for i, player in pairs(playersInRound) do
		if player and player.Parent then
			msg = msg..player.Name..", "
		else
		if not player and player.Parent then
		msg2 = msg2..player.Name..", "
		end
	end
end
	Status.Value = msg.." Survived!"
	Status.Value = msg2.." Game Over! Everyone Died!"
1 Like