Im trying to make a script that gets a table “requests” that contains various user id’s that im trying to get to add a player to a waiting queue. When i add more than 2 people to the queue the script gives an error:
Players.DisastrousFate.PlayerGui.OutfitQueue.LocalScript:21: attempt to index nil with ‘Destroy’
I think the cause is that my value variable isnt updating when run. Why is this?
Edit: I think the issue is that the in pairs loop is messing it up. how do i fix it
Code:
local players = {}
game.ReplicatedStorage.GetQueue.OnClientEvent:Connect(function(requests, currentid, targetusername, isrunning)
for _,v in pairs(requests) do
table.insert(players, v)
print(table.find(players, v))
local clone = game.ReplicatedStorage.QueueExample:Clone()
clone.Name = v
local text = v
clone.Username.Text = v
clone.Parent = script.Parent.Frame.Frame.Folder
--======MAIN=======
for index,value in pairs(players) do
print("here!")
if players[table.find(players, v)] ~= value then --1, 1231231, 2, 132123213
print("NO!")
print(players[table.find(players, v)], "old: "..value) ---VALUE NOT UPDATING. CAUSING ERROR WHEN CALLED MORE THAN 2 TIMES
table.remove(players, value)
script.Parent.Frame.Frame.Folder:FindFirstChild(value):Destroy()
end
end
--======MAIN======================
end
end)
game.ReplicatedStorage.GetQueue.OnClientEvent:Connect(function(requests, currentid, targetusername, isrunning)
for _,v in pairs(requests) do
local players = {}
print(requests)
table.insert(players, v)
print(table.find(players, v))
local clone = game.ReplicatedStorage.QueueExample:Clone()
clone.Name = v
local text = v
clone.Username.Text = v
clone.Parent = script.Parent.Frame.Frame.Folder
print(players)
--======MAIN=======
for index,value in pairs(players) do
print("Value : "..value)
print("here!")
if players[table.find(requests, value)] ~= value then --1, 1231231, 2, 132123213 -- 247535, 247535 OR
print("NO!")
print(players[table.find(requests, players)], "old: "..value) ---VALUE NOT UPDATING. CAUSING ERROR WHEN CALLED MORE THAN 2 TIMES
else
return
end
table.remove(players, value)
script.Parent.Frame.Frame.Folder:FindFirstChild(value):Destroy()
print(players, value)
value = nil
end
--======MAIN======================
end
end)