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

My tournament script is giving an error?

Asked by
Relatch 550 Moderation Voter
9 years ago

So basically, the script gives the error "ServerScriptService.MainScript:29: attempt to get length of local 'tabOfPlayers' (a nil value)". This is on line 29, and I'm not sure why. I explained what 'tabOfPlayers' is in the function, so I have no other ideas. Help?

function handlePlrs(tabOfPlayers)
    local plr1,plr2 = selectPlrs(tabOfPlayers)
    plr1.Character:MoveTo(chosenmap.Spawn1.Position)
    plr2.Character:MoveTo(chosenmap.Spawn2.Position)
end

function Match()
    if not gamedebounce then
        gamedebounce = true
        local function Intermission()
        for i = intermissiontime, 0, -1 do
            if #playingplayers > requiredplayers then
                gui.Text = "Intermission: "..i
            else
                gamedebounce = false
            return
                end
            end
           wait(1)
        end
        Intermission()
        wait(15)
        selectPlrs()
        wait(5)
        handlePlrs()
        gameInPlay = true;
    end
end

while wait() do
    if #playingplayers >= requiredplayers and not gameInPlay then
        Match()
    end
end

Variables:

local gamedebounce = false

local playingplayers = {}
local gametime = 30
local intermissiontime = 15
local requiredplayers = 2
local gui = game.Workspace.ControlBoard.Holder.Mode
local gameInPlay = false;

2 answers

Log in to vote
0
Answered by 9 years ago

You haven't defined anything when calling your handlePlrs function on line 25, thus making tabOfPlayers a nil value and thus causing the error as tabOfPlayers is not existant.

You can get a table of players by using the GetPlayers method of the Players service, as it gets every player in the service and puts it into an array. This is practically the same as GetChildren, but only gets objects that are players.

To solve this problem, you need to do this instead of what you're doing on line 25:

handlePlrs(game.Players:GetPlayers())
0
To add on, you also haven't defined anything in your call to the selectPlrs function a few lines above the call to the handlePlrs function. Spongocardo 1991 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

Print out the array #tabOfPlayers and see what is printed out, if nothing is printed out, the array is empty, that would explain that it is returning nil. Add this print line after line 29

print(table.concat(tabOfPlayers, '; '))
0
array? Relatch 550 — 9y
0
um yes, #tabOfPlayers is an array, the way you are using it dragonkeeper467 453 — 9y
0
Table, not array. EzraNehemiah_TF2 3552 — 9y
0
my bad dragonkeeper467 453 — 9y

Answer this question