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

How would I do this?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I wanted to know how to make a part of a script where if all the players died then the round ends and resets the timer back to zero.

Round Code:

function roundCountdown()
    for roundMinute = 2,0,-1 do
        for roundSecond = 59,0,-1 do
            playerNotification('Time left!')
            playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond))
            wait(1)
        end
    end
end

1 answer

Log in to vote
0
Answered by
xApRix 25
9 years ago
game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function()
        local GameValue = Instance.new("BoolValue")
        GameValue.Parent = Player.Character
        GameValue.Name = "InGameValue"
    end)
end)

--The above adds in the "InGameValue" value every time the player spawns.


function CheckPlayers()
    local InGameNum = 0 --The number of players in game
    for _,v in pairs(game.Players:GetChildren())do --Scroll through players
        local Character = v.Character
        if Character then --Make sure the player's character is not nil
            local InGameValue = Character:FindFirstChild("InGameValue")
            if InGameValue and InGameValue == true then --Make sure the player's humanoid is not nil and health is above 0
                InGameNum = InGameNum + 1 --Add to the number of players alive
            else
                print(Player.."'s InGameValue not found")
            end
        else
            print(Player.."'s Character not found")
        end
    end
    if InGameNum == 0 then --Check to see if everyone is dead
        return false --Return that everyone is out of the game
    elseif InGameNum ~= 0 then
        return true --Return that someone is still in the game
    else 
        return nil
    end
end

function roundCountdown() 
    for roundMinute = 2,0,-1 do 
        for roundSecond = 59,0,-1 do 
            playerNotification('Time left!') 
            playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond)) 
            local CheckInGame = CheckPlayers()
            if CheckInGame == false then
                roundSecond = 0
                --You may have to "break" after seting it to 0, I'm not sure.
            elseif CheckInGame == true then
                print("There are still people in the game")
            end
            wait(1) 
       end 
    end 
end 

This code goes after you teleport the players:

--Assuming you already have the player under "game.players".
local PlayerInGameValue = player.Character.FindFirstChild("InGameValue")
if PlayerInGameValue  then
    PlayerInGameValue.Value = true
else
    print("Can not find: 'InGameValue'")
end

This should work, it does require you to set the value of "InGameValue" located in the player's character to true when you place him in a round though.

0
It doesn't seem to work at all. It just skips to the end of the round once it round even starts. I was wondering how I could use it with IntValues. For example, if everybody's 'Playing' value is equal to zero then it ends the round. Vestralix 15 — 9y
0
Just edited it, It should work now. Remember to set the value of "InGameValue" to true when the players enter a round/minigame. xApRix 25 — 9y
0
Still not working, it does the same thing as before. Vestralix 15 — 9y
0
Did you set the "InGameValue" to true when the players entered a round? xApRix 25 — 9y
Ad

Answer this question