Im trying to make an outfit loading system but im struggling to create a queueing system like the one below:
How would i go around implementing a system like this?
Here is my existing code:
local httpService = game:GetService("HttpService")
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits?itemsPerPage=50"
local requests = {}
local proxyHttp = require(game.ServerScriptService.ProxyRobloxAPI:Clone())
local checkPlayer = function()
if #requests >= 1 then
local userId = (requests[1])
table.remove(requests, table.find(requests, userId))
local s, x = pcall(function()
local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2)
if data then
game.Workspace.Map.Outfits:ClearAllChildren()
local outfits = data.data
for i, v in pairs(outfits) do
local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
local c = game.ServerStorage.BaseAvatar:Clone()
c.Name = v.name
c.Parent = workspace.Map.Outfits
c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
c.Humanoid.NameDisplayDistance = 50
c.Humanoid:ApplyDescription(desc)
c.HitBox.Position = c.HumanoidRootPart.Position
end
end
end)
if not s and x then warn(x) end
end
end
local loop = function()
while true do
wait(7.5)
if #requests >= 1 then
checkPlayer()
else
repeat game:GetService("RunService").Heartbeat:Wait() until #requests >= 1
end
end
end
game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName)
local s, x = pcall(function()
local targetUserId = game.Players:GetUserIdFromNameAsync(targetName)
if targetUserId ~= nil then
local isOnRequests = false
for i, v in pairs(requests) do
if v == targetUserId then
isOnRequests = true
break
end
end
if isOnRequests == false then
table.insert(requests, targetUserId)
if #requests == 1 then
checkPlayer()
end
return "Put in queue!"
else
return "User is already on list!"
end
else
return "User doesn't exist!"
end
end)
if not s and x then warn(x) end
end
coroutine.wrap(loop)()
Client Code:
local players = {}
game.ReplicatedStorage.GetQueue.OnClientEvent:Connect(function(requests, currentid, targetusername, isrunning)
for _,v in pairs(requests) do
table.insert(players, v)
local clone = game.ReplicatedStorage.QueueExample:Clone()
print("yes")
clone.Name = targetusername
clone.Username.Text = targetusername
clone.Parent = script.Parent.Frame.Frame.Folder
--How do i remove from the table when #"requests" changes
end
end)
Game im trying to recreate:
https://www.roblox.com/games/4984400432/NEW-Outfit-Loader