I posted this yesterday but I did not get a response on how to do it but how to keep exploiters from chaining the value.
How would I make a script that once all player have died the game will end? I rather not use values but use a table and remove each player. I am just not sure how to make the table and remove the players.
Thanks, Game
To detect if someone died, you would use the Died
event of Humanoid objects.
-- We declare a variable 't' to hold our table. It is initially empty. local t = {} game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.Died:connect(function() -- Oops. Someone died. We add them to the table. table.insert(t, player) end) end) end)
To check if everyone is dead, it is simply a matter of looping through all connected players and see if someone is missing in the table:
local function isEveryoneDead() for _, v in pairs(game.Players:GetPlayers()) do if not t[v] then -- A player is not in the table. return false end end -- All players are dead. return true end -- [...] if isEveryoneDead() then -- If everyone is dead then empty the table and react appropriately. t = {} end
Hope this helped. If it did, please make sure to mark my answer as accepted and optionally upvote; It helps both of us. :)
Well, Alot of help is on youtube also. Maybe you should look up humanoids. If all players health reaches 0, the game will end. You can ask more questions about different things involved in this question. I hope this helped.