local RS = game:GetService("ReplicatedStorage")
local Queue = RS.Events.Queue
local WaitingQuenue = {}
local InQuenue = {}
Queue.OnServerEvent:Connect(function(Player)
print("Added Player")
table.insert(WaitingQuenue ,Player)
print(WaitingQuenue[1])
if #WaitingQuenue >= 2 then
if #InQuenue > 2 then return end
print("Added to New Quenue")
table.remove(WaitingQuenue, Player)
table.insert(InQuenue, Player)
end
end)
I want to remove a player out of one table to another table. How would I easily do this?
Line - table.remove(WaitingQuenue, Player)
I want to remove a player from one table to NewQuenue.
Since you used table.insert then you can utilize table.find to get the index and then remove it that way.
local exists = table.find(WaitingQuenue, Player)
if exists then
table.remove(WaitingQuenue, exists)
end
But there is something else to note with your code, if you just updated that to remove it will only put the last player joining the queue into the InQuenue table, leaving the first queue person in the waiting queue. Instead you would want to create another function which itterates through your waitingqueue table, clears them out and puts them into the new table.
You can also try this method…
local function MoveToInQueue()
for _, v in ipairs(WaitingQuenue) do
table.insert(InQuenue, v)
v = nil
end
end
You need to do table.remove(WaitingQuenue, arrayvalue), lets say I had a table like this:
local yes = {"Apple", "boo"}
local no = {}
print(yes[1]) -- would print "Apple"
print(yes[2]) -- would print "boo"
I would like to remove “apple” from the table variable, yes, and insert it into the other table.
local yes = {"Apple", "boo"}
local no = {}
wait(1)
table.remove(yes, 1) -- would remove the first array, apple, from "yes"
table.insert(no, "Apple") -- inserts it into the new table
you can also do tablename[array] = nil, but the other method is easier.