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

When all Players are dead, restart the game?

Basically, I want to make a L4D concept. Everyone is in the lobby, upon game start all players are put on team 'Players' and warped to the map . On death, they are placed back in 'Lobby'. But my script doesn't recognize when everyone has died, not resetting the game, and leaving everyone trapped in 'Lobby'.

local start = Instance.new("Hint")
start.Parent = game.Workspace
start.Text = "Starting Game."
wait(1)
start.Text = "Starting Game.."
wait(1)
start.Text = "Starting Game..."
wait(1)
start.Text = "Starting Game."
wait(1)
start.Text = "Starting Game.."
wait(1)
start.Text = "Starting Game..."
wait(1)
while true do
local start = 10

local hint = Instance.new("Hint") 
hint.Parent = game.Workspace 
for i = 1,start do
hint.Text = start - i 
wait(1) 
end
hint.Text = "Starting Game."
wait(2)
hint:remove()


function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor
    if player.Character then
        player:LoadCharacter()
    end
end


for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "Players")
end

target = CFrame.new(10, 0.5, 10)
for i, player in pairs(game.Players:GetChildren()) do
	player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
end
end

The script to change team upon death:

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character) 
repeat wait() until Character:FindFirstChild("Humanoid") ~= nil 

Character.Humanoid.Died:connect(function() 
if Player.TeamColor == game.Teams.Players.TeamColor then 
Player.TeamColor = game.Teams.Lobby.TeamColor 
end
end)
end)

end)

1 comment

0

i have the same problem, have you figured out how to restart the workspace. or reset the game?

1 answer

I would set it up like this: Have a script that updates a variable based on the number of Players in the game, get the number of children every few seconds and update it. (NumberValue.Value = 10)

and have a Variable that gets reset every round that adds 1 when a player dies. So now you have: PlayersInGame(NumberValue) PlayersDied(NumberValue)

now have your other script recognize when PlayersDied => PlayersInGame

Perform your function once you have verified that the number of players died is equal to or more than the number of players who are in the game.

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