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

How to add a check to this script? Please help!

Asked by
xuefei123 214 Moderation Voter
9 years ago

So I am trying to make a mini game game, however I have no clue on how to add a check to see if all players have died, can someone help me?

So here is the script.

wait(2)
local select = script.Rounds:GetChildren()
local h = script:WaitForChild("Status")
function start()
    if game.Players.NumPlayers >= 1 then
        wait(3)
        wait(1)
        h.Value = "Choosing gamemode!"
        local roundchosen = math.random(1, #select)
        wait(.1)
        local round = select[roundchosen]
        print("Chosen round: " .. round.Name)
        wait(3)
        if round.Name == "FFA" then
            FFA()
        elseif round.Name == "DODGEMS" then
            DODGEMS()
        elseif round.Name == "SFFA" then
            h.Value = "Gamemode chosen: " .. round.Name
            wait(3)
            SFFA()
        end
    else
        h.Value = "Waiting for 2 players too start!"
        wait(1)
        start()
    end 
    end

    function SFFA()
        local maps = game.Lighting.Maps.FFA:GetChildren()
        h.Value = "Choosing map.."
        wait(3)
        print("Map selection")
        local mapchosen = math.random(1, #maps)
        local map = maps[mapchosen]
        print(map.Name)
        wait(4)
        local mapclone = map:Clone()
        mapclone.Parent = game.Workspace
        mapclone:MakeJoints()
        wait(4)
        for _, player in pairs(game.Players:GetPlayers()) do
            local contestants = {}
            table.insert(contestants, player)
            local spawnmodel = map.Spawns:GetChildren()
            local spawn = math.random(1, #spawnmodel)
            local spawnchosen = spawnmodel[spawn]
            player.Character.Torso.CFrame = CFrame.new(spawnchosen.Position + Vector3.new(0, 3, 0))
            spawnchosen:Destroy()
        end
        for i = 60, 1, -1 do
            h.Value = "Time left: " .. i -- The check would go here.
            wait(1)
        end
        start()
    end

1 answer

Log in to vote
0
Answered by 9 years ago
function OnDied()
for i,v in pairs(game.Players:GetChildren()) do
if v.Character then
if v.Character.Humanoid.Health == 0 then
print("player had died")
end
end
end
end

local c = coroutine.resume(coroutine.create(function() OnDied() end))

Add the variable c in the spot you want to check if a player has died, add the function before the main code.

0
Umm so where u do the loop just put local c?? xuefei123 214 — 9y
0
Put the whole local c line *local c = coroutine.resume(coroutine.create(function() OnDied() end))* after line 53 in your script. TheZankonator -2 — 9y
0
Umm so if I just put it there, it will just do the function, how do I make it stop the function if only 1 or 0 people are left? xuefei123 214 — 9y
0
Bump xuefei123 214 — 9y
0
Are all your alive players gonna be in the contestants table? So you want them removed from there when they die too? TheZankonator -2 — 9y
Ad

Answer this question