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

How would I add a "stalemate" condition to this script?

Asked by
yodafu 20
5 years ago

Hello everyone, I am in the process of building and scripting a battle royale game and I've pretty much got everything done apart from one thing; a stalemate. This can happen if the last two players standing are killed by the same bomb, and that way there is no winner. When this happens, the last two players get teleported back to the lobby and the timer continues ticking down until 0, and only then does the game continue and start a new round.

Here is my script so far...

local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
    local plrs = game.Players:GetChildren()
    if #plrs > 1 then
    t = 15
    repeat
        t = t-1
        s.Value = "Intermission..."..t
        wait(1) 
    until t == 0
    s.Value = "Game starting!"
    wait(3)
    local mapselect = game.ReplicatedStorage.Games:GetChildren()
    local choose = math.random(1,#mapselect)
    curnum=0
    for i =1,#mapselect do
        curnum = curnum+1
        if curnum == choose then
            mapselect[i]:Clone().Parent = workspace
            curmap = mapselect[i].Name
            s.Value = ""
        end
    end
    wait(3)
    local plrs = game.Players:GetChildren()
    for i = 1,#plrs do
        local num = math.random(1,8)
        plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
        plrs[i].Character.Parent = workspace.Ingame
    end
    t=120
    repeat
        t = t-1
        s.Value = t.." seconds left"
        wait(1)
    local ingame = workspace.Ingame:GetChildren()
    until t ==0 or vals.Winner.Value ~= "" or #ingame == 1
    local ingame = workspace.Ingame:GetChildren()
    if #ingame == 1 then
        vals.Winner.Value = ingame[1].Name
        s.Value = vals.Winner.Value .. " has won!"
        game.Players[vals.Winner.Value].leaderstats.Points.Value =game.Players[vals.Winner.Value].leaderstats.Points.Value +50
        game.Players[vals.Winner.Value].leaderstats.Wins.Value =game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
        vals.Winner.Value = ""
    end
    if vals.Winner.Value ~= "" then
        s.Value = vals.Winner.Value.. " has won!"
                game.Players[vals.Winner.Value].Leaderstats.Points.Value =game.Players[vals.Winner.Value].Leaderstats.Points.Value +50
        game.Players[vals.Winner.Value].Leaderstats.Wins.Value =game.Players[vals.Winner.Value].Leaderstats.Wins.Value +1
        vals.Winner.Value = ""
    end
    if t < 1 then
        s.Value = "No one has won!"
        vals.Winner.Value = ""
    local ingame = workspace.Ingame:GetChildren()
    if #ingame == 0 then
        s.Value = "No one has won!"
        vals.Winner.Value = ""
    end
    end
    wait(3)
    local ingame = workspace.Ingame:GetChildren()
    for i =1,#ingame do
        local plr = game.Players:GetPlayerFromCharacter(ingame[i])
        plr:LoadCharacter()
    end
    workspace[curmap]:Destroy()
    else
        s.Value = "Two or more players are needed to play."
        wait(1)
        end
end

I have tried adding a piece of code underline 40, which reads

if #ingame == 0 then
    s.Value = "No one has won!"
    vals.Winner.Value=""

However, this doesn't seem to work as yet again, the two final players are teleported back to the lobby as the timer runs down.

Any help is appreciated!

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago

The repeat loop:

repeat
    t = t-1
    s.Value = t.." seconds left"
    wait(1)
    local ingame = workspace.Ingame:GetChildren()
until t ==0 or vals.Winner.Value ~= "" or #ingame == 1

will continue, when there are 0 players. Change line 39 to:

until t ==0 or vals.Winner.Value ~= "" or #ingame < 2

It will interrupt, when there are one or zero players (less than two).

0
Thanks for the answer! Would you know how to add a message saying "no one has won!" afterwards by any chance? yodafu 20 — 5y
Ad

Answer this question