Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What should I do to make the round end automatically when everyone dies?

Asked by 3 years ago

There is a script.

local maps = game:GetService("ServerStorage").Maps:GetChildren()
local Title = game.StarterGui.MapSelector.Title
local spawns = game.Workspace.Spawns:GetChildren()
local status = game.ReplicatedStorage.Status
local start = game.Workspace.Start
ti = 0

while true do
    start.CanCollide = true
    ti = 16
    repeat
        ti = ti -1
        status.Value = "Intermission: "..ti.. "s"
        wait(1)
    until ti == 0

    local randomMap = maps[math.random(1, #maps)]
    randomMap:Clone().Parent = workspace
    current = randomMap.Name

    status.Value = "Chosen game is "..randomMap.Name
    wait(5)
    status.Value = "Loading game!"
    wait(2)
    local plrs = game.Players:GetChildren()

    for i = 1, #plrs do
        local randomSpawn = spawns[math.random(1, #spawns)]
        plrs[i].Character.HumanoidRootPart.CFrame = CFrame.new(randomSpawn.Position)
    end
    status.Value = "3"
    wait(1)
    status.Value = "2"
    wait(1)
    status.Value = "1"
    wait(1)
    status.Value = "GO"
    wait(1)
    start.CanCollide = false
    ti = 61
    repeat
        ti = ti -1
        status.Value = "Time Left: ".. ti.."s"
        wait(1)
    until ti == 0
    for i = 1, #plrs do
        plrs[i].Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame + Vector3.new(0, 10, 0)
    end

    workspace[current]:Destroy()
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You could alter your script a bit., instead of repeat you should use something like

for i = 10,0,-1
  status.value = "time left:"..i.."s"
  wait(1)
  if #players == 0 then
    print("round end!")
end

Ok so don't use this because i don't think I did the indentation correctly but you will get the idea - using a for loop will continuously run your script and is an alternate to repeat, it will also display your time left while checking the amount of players left!

Hope this helps!

Any questions? Just ask!

Ad

Answer this question