Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

All players dies if blue kills the entire red team. does anyone know how to help me?

I have a script for an intermission, for a round. I need a script for the end of the round. If blue kills the entire red team, then all players die. Can I create such a script?

Script

while true do
local tvalue = script.Parent.StatusTag

function beginGame()
	for i = 45, 0, -1 do
		wait(1)
		tvalue.Text = "Intermission: " .. i .. "" 
		if i == 0 then
			tvalue.Text = "Game Started!" 
        wait(0,1)
target = CFrame.new(-635, 16.6, 456) 
for i, player in ipairs(game.Players:GetChildren()) do 
   if player.Character and player.Character:FindFirstChild("Torso") then 
      player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0) 
            wait(0,1)
      local plrs = game.Players:GetPlayers()
local chosenPlr = plrs[math.random(1,#plrs)] 
if chosenPlr.Character and chosenPlr.Character:FindFirstChild("HumanoidRootPart") then
   chosenPlr.Character.HumanoidRootPart.CFrame = CFrame.new(-735, 0.6, 537)
            wait(0,1)
for i = 180, 0, -1 do wait(1) tvalue.Text = "Round: " .. i end
            wait(1)
tvalue.Text = "Survivors Win!"
            wait(2)
 p = game.Players:GetChildren()
            wait(0,1)
for i = 1,#p do
p[i].Character.Head:remove()
end
end	
	end
end
       end
    end
end
if game.Players.NumPlayers > 0 then 
	beginGame()
else
	tvalue.Text = "Needs 2 or more player(s) to begin." 
end
end

4 comments

0

Instead of p[i].Character.Head:remove() on line 386, you can just access their humanoid and change their health to 0. And from line 21 t0 381, you can just use a for loop like with intermission, i.e:

0

for i = 180, 0, -1 do wait(1) tvalue.Text = "Round: " .. i end

0

thanks

0

If there are 0 players left in the red team then the game ends and Tvalue.text = "Killer Win". You know how to do it?

1 answer

✓ Accepted answer

This should work if you rename the team1 and team2 variable values to the appropriate teams. It basically stores a value inside each player in the red team that is set to true after they die, and if all values are true after someone dies, the script kills everyone.

local team1Name = "Red team"
local team2Name = "Blue team"

local team1 = game:GetService("Teams")[team1Name]
local team2 = game:GetService("Teams")[team2Name]

team1.PlayerAdded:Connect(function(plr)
	local hasDied = Instance.new("BoolValue")
	hasDied.Parent = plr
	hasDied.Value = false
	hasDied.Name = "hasDied"
end)
team1.PlayerRemoved:Connect(function(plr)
	if plr:FindFirstChild("hasDied") then
		plr.hasDied:Destroy()
	end
end)

function checkIfAllPlayersDead()
	local plrs = team1:GetPlayers()
	for _,plr in pairs(plrs) do	
		if plr:FindFirstChild("hasDied") then
			if plr.hasDied.Value == false then return end
		end
	end
	--all players have died:
	for _,plr in pairs(game.Players:GetPlayers()) do
		if plr.Character then
			plr.Character:BreakJoints()
		end
		if plr:FindFirstChild("hasDied") then
			plr.hasDied.Value = false
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Died:Connect(function()
			if plr.Team == team1 then
				if plr:FindFirstChild("hasDied") then
					plr.hasDied.Value = true
				end
				checkIfAllPlayersDead()
			end
		end)
	end)
end)

Also, you should use a loop for the countdown timer (make sure the code above is above the timer code in the script):

for i = 180,0,-1 do
	tvalue.Text = "Round: " .. i
end

This discussion is preserved as it was. New answers, comments, and votes are closed.