How to make all the people that are alive win?

So im making this round bases game where u have different kind of ‘Gamemodes’. I finished the Race gamemode yesterday where a max of 3 people would win when they reach the end.

Now i want to create a gamemode that whoever still lives at the end of the round or only 1 player is left wins. I already create a elseif statement but i couldnt get it to work, any tips or tricks?

(codes below the problem starts at the elseif roundtype survival)

local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()

while true do
	status.Value = "Waiting For Players"
	repeat task.wait() status.Value = "Waiting for a player to join" until #game.Players:GetPlayers() >= 1
	if #game.Players:GetPlayers() >= 1 then
		status.Value = "Starting"
		for i = 1,15 do
			status.Value = "Next round will start in: "..15-i
			wait(1)
		end

		local rand = math.random(1, #maps)

		local map = maps[rand]:Clone()
		map.Parent = workspace

		status.Value = "The next minigame is: "..map.Name
		wait(5)


		local players = game.Players:GetChildren()
		for i = 1,#players do
			if players[i].Character ~= nil then
				local spawnLocation = math.random(1,#map.Teleports:GetChildren())
				players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLocation].Position)
				players[i].Character.Parent = workspace.Ingame

			end
		end

		local winners = {}
		local roundLenght = 60
		local canWin = true
		local roundType = ""

		if map:FindFirstChild("Race") then
			roundType = "Race"
			map.WinnerPart.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
					if #winners <= 3 then -- checks amount of values in the table
						local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
						if not table.find(winners,plr.Name) then
							table.insert(winners,plr.Name)
							status.Value = hit.Parent.Name.." Has won!"
							wait(1)
							plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
							plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value +100
							plr:LoadCharacter()
						end
					else
						canWin = false
					end					
				end
			end)
		elseif map:FindFirstChild("Survival") then
			roundType = "Survival"
            
			
		end
        if roundType == "Race" then
		repeat
			roundLenght = roundLenght -1
			status.Value = "Time left: "..roundLenght.."\n Current Winners: "..table.concat(winners,",")
			wait(1)
		    until roundLenght == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0
		    status.Value = "Winner(s): "..table.concat(winners,",")
		wait(3)
			table.clear(winners)

		wait(3)
		map:Destroy()
			
		end 
		local players = game.Players:GetChildren()
		for i = 1,#players do
			if players[i].Character ~= nil then
				players[i]:LoadCharacter()
			end
		end
    end
end

I’ve been trying a bunch of things, but still doesn’t work. Anyone got some input? :sweat_smile:

Check if the humanoid’s health of the people that are left over 0

What exactly do you mean by this?

In this block of code here, check if the humanoid’s health is over 0 before determining if they are a winner or not

That’s the block of code for the race game type, we don’t need to touch that.

We have to make something happen after this

1 Like

Hi, Make a Team for alive and spectator when the Player dies he goes to the Spectator, when the round ends give the win to the alive team.
That’s how you check if the Player is on a Team.


	if Player.Team == game.Teams.Alive then

	end

What line of code do I have to use to create a team, or do I have to make this manually?. Also maybe it would be possible to give every player a string value named winners at the begin of the round, when u die u lose the value and at the end whoever has the winner value wins?. But I’m just a few months into scripting and I don’t really know how to translate this to code… Any idea?

1 Like

Yeah, you could do that there are a lot of ways to do it, Firstly what you have said (Using Values), Teams, Tables.

If you would like to give with the Teams way you will see a Team Service in your explorer window press the Plus button and 2 Teams “Spectator” and “Alive”

When the Round ends (You’ve probably have the code for it)
Add this code

if Player.Team == game.Teams.Alive then

end

if you would like to go with the Tables you will have to have a Table called “Winners”
When the Round ends add the People that won

local Winners = {}

-- When the Round ends

table.Insert(Player, Winners)

For the Values, it is really easy when the round starts give everybody a BoolValue it will be set to false, when the Round ends and there are Winners The BoolValue will be set to true and check if the BoolValue is set to true, if it is then give them the Reward

1 Like

Do people join those team automatically?. And u can look what I already have at the start of the topic, I posted my whole script there.

Make the Spectator Team AutoAssignable on
While the Alive team off.
I’ve provided you the ways how you could do it, Roblox doesn’t allow to give full scripts sadly because it’s against the rules.

I’ll play around with it and let you know if I get it to work.

Just for learning purposes why a BoolValue and not a Intvalue or String value? I just don’t know the difference and when to use which, maybe you can explain me? :sweat_smile:

You could use any of them if you would like but the BoolValue would be better. Because it’s just off and on While IntValue is any number I’m guessing you might do it 0 or 1, which is a bit inefficient
For string values, sure you could use that But the BoolValue seems easier because it has more logic.

Thanks! So what line of code should I use to give everyone a BoolValue when the round starts, and remove it when they die?.

I’m sorry if I sound like a monkey :see_no_evil:

1 Like

Give the BoolValue when the Round starts make sure it’s value is false, then when the game ends make all the winners boolvalue to true and give them the reward, for the people who died in- round remove it when they die, After the winners get the reward just remove their BoolValue.

1 Like
local winnersvalue = Instance.new("BoolValue")

elseif map:FindFirstChild("Survival") then
			roundType = "Survival"
			winnersvalue = false

I made this right now, so how would i be able to give the players the BoolValue?

Actually, I got a better Idea, when the Player joins you would give them a BoolValue to theirs called “Winner” When the Round Starts make sure it’s false
When the Player dies it will still be false, when the round ends and Player wins make the BoolValue to true.

Here is the script for giving boolValue when Player joins

game.Players.PlayerAdded:Connect(function(Player)

local WinnerValue = Instance.new("BoolValue")
WinnerValue .Name = "WinnerValue"
WinnerValue.Parent = Player

end)

When the Round starts script We make the Value to false.

Player.WinnerValue.Value = false

When the Round ends script

-- give the Players reward (ex coins,etc)
Player.WinnerValue.Value = false -- Already finished the game and gave everybody who won the Reward.
local WinnersValue = game.Players:FindFirstChild("Winner")
elseif map:FindFirstChild("Survival") then
			roundType = "Survival"
			WinnersValue = false
			if roundLenght == 0 then
				WinnersValue = true

I made this block of code now, so how would i be able to check if the player died and set the value back to false?

(I added the creation of the WinnerValue to my leaderstats script)

This is wrong, you have to get the Player Winner Value not the game.Players.Winner value.

Could I see your full script?

Small mistake that you did, Should be WinnersValue.Value

Here you check if the Player has died and if he did WinnerValue will be false.

Player.Character.Humanoid.Died:Connect(function()
       WinnersValue.Value = false
end)
local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()

while true do
	status.Value = "Waiting For Players"
	repeat task.wait() status.Value = "Waiting for a player to join" until #game.Players:GetPlayers() >= 1
	if #game.Players:GetPlayers() >= 1 then
		status.Value = "Starting"
		for i = 1,15 do
			status.Value = "Next round will start in: "..15-i
			wait(1)
		end

		local rand = math.random(1, #maps)

		local map = maps[rand]:Clone()
		map.Parent = workspace

		status.Value = "The next minigame is: "..map.Name
		wait(5)


		local players = game.Players:GetChildren()
		for i = 1,#players do
			if players[i].Character ~= nil then
				local spawnLocation = math.random(1,#map.Teleports:GetChildren())
				players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLocation].Position)
				players[i].Character.Parent = workspace.Ingame

			end
		end

		local winners = {}
		local roundLenght = 60
		local canWin = true
		local roundType = ""
		local WinnersValue = game.Players:FindFirstChild("Winner")
		
		if map:FindFirstChild("Race") then
			roundType = "Race"
			map.WinnerPart.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
					if #winners <= 3 then -- checks amount of values in the table
						local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
						if not table.find(winners,plr.Name) then
							table.insert(winners,plr.Name)
							status.Value = hit.Parent.Name.." Has won!"
							wait(1)
							plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
							plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value +100
							plr:LoadCharacter()
						end
					else
						canWin = false
					end					
				end
			end)
		elseif map:FindFirstChild("Survival") then
			roundType = "Survival"
			WinnersValue = false
			if roundLenght == 0 then
				WinnersValue = true
			end
		end
        if roundType == "Race" then
		repeat
			roundLenght = roundLenght -1
			status.Value = "Time left: "..roundLenght.."\n Current Winners: "..table.concat(winners,",")
			wait(1)
		    until roundLenght == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0
		    status.Value = "Winner(s): "..table.concat(winners,",")
		wait(3)
			table.clear(winners)

		wait(3)
		map:Destroy()
			
		elseif roundType == "Survival" then
			
		end 
		local players = game.Players:GetChildren()
		for i = 1,#players do
			if players[i].Character ~= nil then
				players[i]:LoadCharacter()
			end
		end
    end
end

this is my full script. The race gametype works, but now i want to add the Survivale game type but i actually have no idea where to start the block of code