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

If all players have a value set to false?

I'm making a game and I want to know if everyone has died.

while true do wait()
	local allFalse = true
	if game.ServerStorage.Game.GameRunning.Value == true then
		for _, player in pairs(game.Players:GetPlayers()) do
			if player.Values.IsPlaying.Value == true then
				allFalse = false
				break
			end
		end
	end

	if allFalse == true then
		print("Game Over.")
	end
end

When someone dies the IsPlaying value is set to false. The GameRunning value is just a value thats true when the game is running.

Right now I just get the Game Over message spammed in the console.

I'd really appriciate some help! ^_^

2 answers

Just add bool value to the player named "Dead" that set false and when Humanoid.Died start function that makes this bool as true

2 comments

0

You can check in pairs if all players value "Dead" is true

0

That doesn't answer my question.

Try this!

local playersAlive = {}

for i, player in pairs(game.Players:GetPlayers()) do
	if player then
		table.insert(playersAlive, player)
	end
end

for i, players in pairs(playersAlive) do
	character = players.Character

	character.Humanoid.Died:Connect(function()
		table.remove(playersAlive, table.find(playersAlive, players))
	end
end

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