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

Issue with picking players for table (round system)?

Asked by
Prioxis 673 Moderation Voter
7 years ago
Edited 7 years ago

What the script should be doing : Pick 2 RANDOM players and add them in a table Teleport 2 random players to map if time runs out kill both players remove them from the table if a player wins remove them from the table and kill them

What the script is doing : Picks first 2 players (I think it's adding all the players to the table) Teleports 2 first players to the map If time runs out kills 1 player (Don't know what goes on in the table) If a player wins kills them (Don't know what happens to the table)

I marked all possible issues with a comment -- here

Don't write a comment saying "We're not going to look through 120+ lines of code" I already marked where the issue's will be I know where they are they've just become out of my expertise..

local replicatedStorage = game.ReplicatedStorage
local status = replicatedStorage:WaitForChild('InfoValue')
local mapstorage = workspace.Mapstorage
local mapinfo = replicatedStorage:WaitForChild("Map")
local plr1 = replicatedStorage:WaitForChild("plr1")
local plr2 = replicatedStorage:WaitForChild("plr2")

_G. InBattle = {} -- here

local intermissionTimer = 30

while true do


    while game.Players.NumPlayers < 2 do
        status.Value = "The game requires a minimum of 2 players please invite a friend or patiently wait.."
        repeat wait(2) until game.Players.NumPlayers >= 2
    end

    game.Players.Changed:connect(function()
        if game.Players.NumPlayers >= 2 then
            intermissionTimer = 30
        elseif game.Players.NumPlayers > 2 and game.Players.NumPlayers <= 8 then
            intermissionTimer = 20
        elseif game.Players.NumPlayers > 8 and game.Players.NumPlayers <= 15 then
        end
    end)

    for i = intermissionTimer,0,-1 do
        status.Value = "Intermission : "..i
        wait(1)
    end

    _G. gameplayers = {} -- here
    for i, v in pairs(game.Players:GetChildren()) do -- here
    if v then
        table.insert(_G.gameplayers, v.Name) -- here
        end
    end

    local mapinserverstorage = game:GetService('ServerStorage'):GetChildren()
    local chosenmap = mapinserverstorage[math.random(1, #mapinserverstorage)]
        mapinfo.Value = chosenmap.Name
        status.Value = "Loading Map : ".. chosenmap.Name
        chosenmap:Clone().Parent = mapstorage
        wait(5)
        status.Value = "Get ready to be teleported!"
        wait(2)
        local spawns = chosenmap:WaitForChild("Spawns"):GetChildren()
        for _, player in pairs(game.Players:GetPlayers()) do -- here
            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)
                    table.insert(_G.InBattle, player.Name) -- here
                    torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))

                    -- give player skin they have                   
                    player:WaitForChild("CurrentSkin")
                    if player['CurrentSkin'].Value == "MissingLink" then
                        replicatedStorage:FindFirstChild("MissingLink"):Clone().Parent = player.Backpack
                    else
                    local sword = replicatedStorage.Sword
                    local newsword = sword:Clone()
                    newsword.Parent = player.Backpack
                    end

                    if plr1.Value == "" then
                        plr1.Value = player.Name
                    else
                        plr2.Value = player.Name
                    end
                    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 25
                    --player:FindFirstChild("InBattle").Value = true

                end
            end
        end

        for i = 60, 0, -1 do
            if i == 0 then
                status.Value = "Time up!"
                if #_G.InBattle == 2 then -- here
                    for i, v in pairs(_G.InBattle) do -- here
                        if v ~= nil then
                            game.Players:FindFirstChild(v).Character:BreakJoints()
                            table.remove(_G.InBattle, v.Name) -- here
                        end
                    end
                end
                break
            end
            wait(1)
            if #_G.InBattle == 1 then -- here
                for i, v in pairs(_G.InBattle) do -- here
                    if v ~= nil then
                        table.remove(_G.InBattle, v.Name) -- here
                        status.Value = v.. " is the Winner!"
                        wait(2)
                        status.Value = "Winner Winner Chicken Dinner!"
                        --game.Players:FindFirstChild(v):FindFirstChild("InBattle").Value = false
                        game.Players:FindFirstChild(v):WaitForChild("leaderstats").Cash.Value = game.Players:FindFirstChild(v):WaitForChild("leaderstats").Cash.Value + 250
                        game.Players:FindFirstChild(v).Character:BreakJoints()
                        game.Players:FindFirstChild(v).leaderstats.Wins.Value = game.Players:FindFirstChild(v).leaderstats.Wins.Value +1                        
                        plr1.Value = ""
                        plr2.Value = ""
                        wait(1)
                        status.Value = "Something Here"
                        break
                    end
                end
                break
            else
                status.Value = i.. " seconds remaining!"
            end
        end
mapstorage:ClearAllChildren()
wait(5)
end

Answer this question