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;
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())
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, '; '))