Hello,
I have written a script which loads the outfits of a player. However, it does not seem to work and I have no clue why. It only loads the current outfit of the player. Can anyone help?
-- SERVICES
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local ss = game:GetService("ServerStorage")
local http = game:GetService("HttpService")
local dss = game:GetService("DataStoreService")
local ins = game:GetService("InsertService")
local mps = game:GetService("MarketplaceService")
-- VARIABLES
local ds = dss:GetOrderedDataStore("TopPlayers")
local event = rs:WaitForChild("HandlerRemote")
local outfit_folder = workspace.PlayerOutfits
local baseChar = ss.BlockRig
local lobby = workspace.Lobby
local spawns = lobby.SpawnPoints
local display = lobby.Display.PlayerDisplay.Main_Frame
local leaderboard = lobby.TopSearched.TopPlayerDisplay.Main_Frame
-- VALUES
local checking = false
local max_points = 144
local innitial = 210
local display_time = 15
local fit_dist = 5
local currentSlot = 0
local maxTopPlayers = 30
local maxActivationDist = 7
-- TABLES
local queue = {}
local trying = {}
-- FUNCTIONS
local function set_canvas(parent : ScrollingFrame)
local n = #(parent:GetChildren())
parent.CanvasSize = UDim2.new(0,0,0,n*innitial)
end
local function create_Clickers(outfit)
local click = Instance.new("ClickDetector")
click.Name = "OutfitTrial_Clicker"
click.Parent = outfit
click.MaxActivationDistance = maxActivationDist
click.MouseClick:Connect(function(plr)
local hum : Humanoid = plr.Character:WaitForChild("Humanoid")
local desc : HumanoidDescription = outfit:WaitForChild("Humanoid"):GetAppliedDescription()
hum:ApplyDescription(desc)
end)
end
local function get_clicks()
for i,v in ipairs(outfit_folder:GetChildren()) do
local clicker : ClickDetector = v:FindFirstChild("OutfitTrial_Clicker")
if clicker then
clicker.MouseClick:Connect(function(plr)
local hum : Humanoid = plr.Character:WaitForChild("Humanoid")
local desc : HumanoidDescription = v:WaitForChild("Humanoid"):GetAppliedDescription()
hum:ApplyDescription(desc)
end)
else
warn("CLK NF: "..v.Name)
end
end
end
local function get_slot()
currentSlot += 1
if currentSlot > max_points then
return nil
end
local slot = spawns["Part"..currentSlot]
return slot.CFrame
end
local function make_prompts(dummy)
local c,p = Instance.new("ClickDetector"), Instance.new("ProximityPrompt")
c.MaxActivationDistance = maxActivationDist
p.MaxActivationDistance = maxActivationDist
c.Parent = dummy
p.Parent = dummy
c.MouseClick:Connect(function(plr)
event:FireClient(plr, "LoadChar", dummy)
end)
p.Triggered:Connect(function(plr)
event:FireClient(plr, "LoadChar", dummy)
end)
end
local function load_outfit(hd, name)
local new = baseChar:Clone()
local anime = script:WaitForChild("Animate"):Clone()
local hum = new:WaitForChild("Humanoid")
anime.Parent = new
new.Parent = outfit_folder
new.Name = name
hum.DisplayName = name
--create_Clickers(new) -- For the Asset Menu
make_prompts(new) -- For the new Try and Buy Asset Menu
local cf = get_slot()
if cf then
new:SetPrimaryPartCFrame(cf)
hum:ApplyDescription(hd)
else
warn("Slots full")
end
end
local function remove_frame(id)
local frame = display.Queue:FindFirstChild("-/\-"..id)
if frame then
frame:Destroy()
end
end
local function add_queue_frame(name, id)
local frame = rs.Storage.QueueFrame:Clone()
frame.Name = "-/\-"..id
frame.FrameOfName.PlayerName.Text = name
pcall(function()
frame.Thumbnail.Image = players:GetUserThumbnailAsync(id, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
end)
frame.Parent = display.Queue
set_canvas(display.Queue)
end
local function addTo_queue(name, from_plr : Player?)
local id
pcall(function()
id = players:GetUserIdFromNameAsync(tostring(name)) or nil
end)
if id then
if not table.find(queue, id) then
table.insert(queue, id)
add_queue_frame(name, id)
if from_plr then
event:FireClient(from_plr, "AddedToQueue", name)
end
local s,e = pcall(function()
local data = ds:GetAsync(id)
if data then
data+=1
ds:SetAsync(id, data)
else
ds:SetAsync(id, 1)
end
end)
if not s then warn(e) end
else
print("Player already in queue")
if from_plr then
event:FireClient(from_plr, "AlreadyInQueue")
else
print("From_Plr : NF")
end
end
else
warn("PDE: "..name)
end
end
local function add_top_frame(name, id, count, order)
local frame = rs.Storage.TopPlayerFrame:Clone()
frame.FrameOfName.PlayerName.Text = name
frame.FrameOfName.Count.Text = "Count: "..count
frame.LayoutOrder = order
pcall(function()
frame.Thumbnail.Image = players:GetUserThumbnailAsync(id, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
end)
frame.Parent = leaderboard.Top_Players
set_canvas(leaderboard.Top_Players)
frame.Button.MouseButton1Click:Connect(function()
addTo_queue(name)
end)
end
local function refresh_board()
for i,v in ipairs(leaderboard.Top_Players:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
local data = ds:GetSortedAsync(false, maxTopPlayers)
local page = data:GetCurrentPage()
for rank, savedData in ipairs(page) do
local id = tonumber(savedData.key)
if id then
coroutine.wrap(function()
local name = players:GetNameFromUserIdAsync(id)
if name then
local count = savedData.value
if count then
add_top_frame(name, id, count, rank)
end
else
print("Failed to retrieve name for user ID:", id)
end
end)()
else
print("Invalid id:", savedData.key)
end
end
end
local function try_v(plr, id)
local asset = ins:LoadAsset(tonumber(id))
local old = nil
if not trying[plr.UserId] then trying[plr.UserId]={} end
for i,v in ipairs(asset:GetChildren()) do
plr.Character.Humanoid:AddAccessory(v)
table.insert(trying[plr.UserId], v)
end
end
-- Triggers
event.OnServerEvent:Connect(function(plr : Player, arg, arg2, arg3)
if arg == "Add_to_Queue" then
addTo_queue(arg2, plr)
elseif arg=="ApplyDesc" then
if trying[plr.UserId] then
for i,v in ipairs(trying[plr.UserId]) do
v:Destroy()
end
end
arg2.Humanoid:ApplyDescription(arg3)
elseif arg == "TryIt" then
try_v(plr, arg2)
end
end)
coroutine.wrap(function()
while task.wait(1) do
for a,fit in ipairs(outfit_folder:GetChildren()) do
fit:Destroy()
end
if #queue==0 then continue end
local id = tonumber(queue[1])
local s,e = pcall(function()
display.Thumbnail.Image = players:GetUserThumbnailAsync(id, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
load_outfit(players:GetHumanoidDescriptionFromUserId(id), "Current Outfit")
local fitData = http:JSONDecode(http:GetAsync("https://avatar.roproxy.com/v1/users/"..id.."/outfits"))["data"]
for a,outfit in ipairs(fitData) do
load_outfit(players:GetHumanoidDescriptionFromOutfitId(outfit["id"]), outfit["name"])
task.wait(0.1)
end
end)
if not s then print(e) end
remove_frame(id)
task.wait(display_time)
table.remove(queue, 1)
currentSlot = 0
display.Thumbnail.Image = ""
end
end)()
coroutine.wrap(function()
while true do
refresh_board()
task.wait(10)
end
end)()
I feel that the problem is with this section of code but I am unsure:
coroutine.wrap(function()
while task.wait(1) do
for a,fit in ipairs(outfit_folder:GetChildren()) do
fit:Destroy()
end
if #queue==0 then continue end
local id = tonumber(queue[1])
local s,e = pcall(function()
display.Thumbnail.Image = players:GetUserThumbnailAsync(id, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
load_outfit(players:GetHumanoidDescriptionFromUserId(id), "Current Outfit")
local fitData = http:JSONDecode(http:GetAsync("https://avatar.roproxy.com/v1/users/"..id.."/outfits"))["data"]
for a,outfit in ipairs(fitData) do
load_outfit(players:GetHumanoidDescriptionFromOutfitId(outfit["id"]), outfit["name"])
task.wait(0.1)
end
end)
if not s then print(e) end
remove_frame(id)
task.wait(display_time)
table.remove(queue, 1)
currentSlot = 0
display.Thumbnail.Image = ""
end
end)()