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

Ending team game when X amount of KOs is reached?

Asked by 6 years ago
Edited 6 years ago

Hello,

I'm having some difficulty with getting my game to end after a team has reached the amount of wins needed for the match to end, in this case 10.

Team Alpha is the Pearl color. Team Omega is the Gold color.

Error outputs I get when messing with it are, "Kills" is a nil value. Kills (and the rest of the leaderstats) are done correctly, and Kills are added when a player KOs another, but I'd like for the match to end when 10 kills for the team is reached. Granted, its possible I've got this portion complete wrong. :D

Here is the portion of the script that specifically addresses this:

--local team1 = BrickColor.new("Pearl"):GetPlayers()
--local team2 = BrickColor.new("Gold")  
local team1 = game.Teams.Alpha:GetPlayers("leaderstats")
local team2 = game.Teams.Omega:GetPlayers("leaderstats")

    if team1.Kills.Value == 10 then
        for i, v in pairs (game.Teams["Alpha"]:GetPlayers()) do
            if v ~= nil then
                status.Value = v..' is the winner!'
                game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 5 -- This number is the amount of Points awarded to the victor.
                game.Players[v].leaderstats.Experience.Value = game.Players[v].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor.
                game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
                break
            end
        end

elseif team2.Kills.Value == 10 then
        for i, v in pairs (game.Teams["Omega"]:GetPlayers()) do
            if v ~= nil then
                status.Value = v..' is the winner!'
                game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 5 -- This number is the amount of Points awarded to the victor.
                game.Players[v].leaderstats.Experience.Value = game.Players[v].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor.
                game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
                break
            end
        end     

And here is the entire match script if the problem appears to be elsewhere:

local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.workspace:WaitForChild('mapStorage')
local StarterGui = game:GetService('StarterGui')



while true do
if game.Players.NumPlayers < 2 then 
    status.Value = 'There needs to be 2 or more players to begin!'
    repeat wait(2) until game.Players.NumPlayers >= 2
end 



--Intermission
for i = 30,0,-1 do  --First number is the length in seconds of the Intermission
    status.Value = 'Intermission '..i
wait(1)
end


_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do

    if v then
        table.insert(_G.gameplayers, v.Name)
    end 
end


-- Random Map selection & Spawns
local h = Instance.new("Hint", game.Workspace)
local mapsinserverstorage = game:GetService('ServerStorage').Maps:GetChildren()
local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
h.Text = "Get ready!"
status.Value = 'Now Loading: ' .. chosenmap.Name .. '! Get ready to be teleported!'


wait(9)
h:Destroy() 
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild('Torso')
        local allspawns = math.random(1, #spawns)
        local randomspawn = spawns[allspawns]
        if randomspawn and torso then 
            table.remove(spawns, allspawns)
            torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))


--Grant team-specific weapons.
local tool1 = game.ReplicatedStorage.AK
local team1 = BrickColor.new("Pearl")

    if player.TeamColor == team1 then
        tool1:Clone().Parent = player.Backpack
end


local tool2 = game.ReplicatedStorage.IceTouch
local team2 = BrickColor.new("Gold")

    if player.TeamColor == team2 then
        tool2:Clone().Parent = player.Backpack
end


print("Removing ForceField1")

local players = game.Players:GetChildren()
for i, plr in ipairs(players) do
    plr.InSafezone.Value = false
end
print("Removing ForceField2")


        end
    end
end


wait(1)


-- Round information
for i = 90, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes.
if i == 0 then

    status.Value = 'Time up!'
    break
end 
    wait(1)


--local team1 = BrickColor.new("Pearl"):GetPlayers()
--local team2 = BrickColor.new("Gold")  
local team1 = game.Teams.Alpha:GetPlayers("leaderstats")
local team2 = game.Teams.Omega:GetPlayers("leaderstats")

    if team1.Kills.Value == 10 then
        for i, v in pairs (game.Teams["Alpha"]:GetPlayers()) do
            if v ~= nil then
                status.Value = v..' is the winner!'
                game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 5 -- This number is the amount of Points awarded to the victor.
                game.Players[v].leaderstats.Experience.Value = game.Players[v].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor.
                game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
                break
            end
        end

elseif team2.Kills.Value == 10 then
        for i, v in pairs (game.Teams["Omega"]:GetPlayers()) do
            if v ~= nil then
                status.Value = v..' is the winner!'
                game.Players[v].leaderstats.Points.Value = game.Players[v].leaderstats.Points.Value + 5 -- This number is the amount of Points awarded to the victor.
                game.Players[v].leaderstats.Experience.Value = game.Players[v].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor.
                game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
                break
            end
        end 


            break
    else
        status.Value = i..' seconds remaining!'
    end
end


mapstorage:ClearAllChildren()
wait(3)
    end
0
why does everyone have floating ends? hiimgoodpack 2009 — 6y
0
and so many blank lines? hiimgoodpack 2009 — 6y
0
What are you referring to with floating ends? And as for the blank lines, I like having space between things. Do you have any suggestions regarding the question I asked? :) Never2Humble 90 — 6y
0
No one? :( Never2Humble 90 — 6y

Answer this question