Hi,
I am trying to modify my game to make it so round ends when everyone dies. But everything I try won't work.
function checkDeadPlayers() if(#deadPlayers == game.Players.NumPlayers) then game.Workspace.running = false deadPlayers = {} end end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character.Humanoid.Died:connect(function() if (player not in deadPlayers) then table.insert(deadPlayers, player) checkDeadPlayers() end) end) end) end)
You cannot test for an element in a list using the keyword "in" - you must use a for loop instead (ideally inside a function).
ex, the one I use:
function Contains(list, item) if list == nil then return false end for i = 1, #list do if list[i] == item then return true end end return false end --ex in your case you'd say "if not Contains(deadPlayers, player) then"
You have a few other problems with your script:
if "workspace.running" is a BoolValue, you need to say "workspace.running.Value = false" (ie assign to its "Value" property), not just "workspace.running = false" (which would attempt to set a property of the workspace to false -- except that the workspace doesn't have a "running" property)
Further, "character.Humanoid.Died" can only ever fire once because every time the player's character is reset, they get a new humanoid. You need to connect the new humanoid to the event. Roblox's leaderboard script does this, you may wish to take a look at it (in particular look at lines 143-146 for hooking up the events for OnPlayerAdded, and also look at the onPlayerRespawned function, which hooks up the new humanoid to the onHumanoidDied function. In your case, you'd replace "onHumanoidDied" with your function to add the player to the list of dead players.)
Also note that, in lua, you do not need parentheses around the condition of an if statement.
Be sure to check for syntax errors: Roblox has a "Script Analysis window" that would tell you of your syntax error on line 10. Attempting to run the script would likewise show you the syntax error in the Output window.