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

I was trying to make a queue system but I keep getting the errors below?

Asked by 2 years ago

Here are the errors,

18:56:21 -- Unable to cast value to object Stack Begin Script 'Workspace.Pad1.Script', Line 40 - function queueLoop Stack End

And here is my code (EVERYTHING FROM ABOVE HAS TO DO WITH THIS CODE):

01  local requiredPlayers = 3
02  local playerQueue = {
03      1,
04      2
05  }
06  local ts = game:GetService("TeleportService")
07  local numOfPlayers = 1
08   
09  local function hasPlayer(tab, ply)
10      for i, v in pairs(tab) do
11          if v == ply then
12              return true
13          end
14      end
15      return false
16  end
17   
18  local function joinQueue(player)
19      if not hasPlayer(playerQueue, player) then
20          if numOfPlayers == 0 then
21              numOfPlayers = 1
22          else
23              if numOfPlayers == 1 then
24                  numOfPlayers = 3
25                  print("player has joined the queue")
26                  playerQueue[numOfPlayers] = player
27              end
28          end
29      end
30  end
31   
32  local function queueLoop()
33      print(1)
34      while wait(1) do
35          print(2)
36          if numOfPlayers == requiredPlayers then
37              print("prepare to teleport")
38              local code = ts:ReserveServer(11299666436)
39              print(3)
40              ts:TeleportToPrivateServer(11299666436, code, playerQueue)
41              print(4)
42              playerQueue = {}
43              print(5)
44          end
45      end
46  end
47   
48  spawn(queueLoop)
49  script.Parent.Touched:Connect(joinQueue)

Answer this question