Hello, I am working on a Queue System for an upcoming project I have planned. My goal is to use a Global Table to store the names of all players who have entered the queue. Here is my code for that portion of the script:
for i,v in pairs(Seats:GetChildren()) do -- list seats
if v.Occupant == nil then -- if seat empty
character.HumanoidRootPart.CFrame = CFrame.new(v.Position + Vector3.new(0,1,0))
character.Humanoid.JumpPower = 0 -- can't leave seat
_G.PlayerList1[player.UserId] = player.Name
print(player.Name .. " added to queue")
print(unpack(_G.PlayerList1))
break -- break the loop because we found our seat
end
end
I’ve already created a variable for the table, it’s just outside of the function. This portion of the script looks for an available seat to place the player in. But it also adds the player to the table. I am using the Player’s UserId as the key to store their name, so it’s easier to remove later. Here is the code i use to remove:
ExitQueue.OnServerEvent:Connect(function(player)
local character = player.Character
character.Humanoid.JumpPower = 50
character.Humanoid.Jump = true
wait(.25)
character.HumanoidRootPart.CFrame = CFrame.new(Return.Position + Vector3.new(0,1,0))
DisableUI:FireClient(player)
-- remove from table
table.remove(_G.PlayerList1, player.UserId)
print(unpack(_G.PlayerList1))
end)
The reason for printing the tables is so I can track whos in the queue at the time. But the issue is, when I test the game, the name of the player doesn’t show up. The table is empty. I’ve tested this with multiple people in game, and same error.
This is considered one of my attemps at solving my main problem, which is removing the player from the table. Any suggestions as to why this is happening? Or an alternative method? ![]()
Edit: I’ve done a lot of research on tables on the Developer Hub, and I can’t find anything to help me.
Edit2: Maybe this has something to do with trying to create a Dictionary instead of an array? I think I need an array.