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

How to make a script recognize when all players have died?

Such as Murder Mystery when all Innocents have died the game restarts. I do not know the process of that, anyone care to explain/demonstrate?

( I have the code thought out I just am struggling on figured this bit out. Any help would be appreciated)

1 answer

✓ Accepted answer

You would probably need a loop to set all values to true when the game starts:

local p = game.Players:GetPlayers()
for i = 1, #p do
	p[i].Alive.Value = true
	print(player.Name .. " is alive.")
end

And while the game is playing:

game:GetService('Players').PlayerAdded:connect(function(player)

local isAlive = Instance.new("BoolValue")
isAlive.Name = "Alive"
isAlive.Value = false
isAlive.Parent = player

	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			print(player.Name .. " has died!")
			player.Alive.Value = false

			local numPlrAlive = 0
			local p = game.Players:GetPlayers()

				for i = 1, #p do
					if p[i].Alive.Value then
						print(player.Name .. " is still alive!")
						numPlrAlive = numPlrAlive + 1
					end
				end

			if numPlrAlive > 0 then
				print("Players are still alive")
			else
				print("Everyone is dead!")
			end
			
		end)
	end)
end)

2 comments

0

Thanks

0

+1

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