Hello, I am trying to make an avatar inventory
system for my game. Basically, when the person accesses the UI, they would see all assets from their character in the UI, like this.
I have two issues with these, first, whenever I open the inventory, it will only get the assets loaded at the time the UI is loaded ( when the player joins the game )
, and whenever I add a new asset it will not update and if I only define it inside the open button function, asset
is nil so it shows nothing.
My code for this is
-- inside the button script
button.MouseButton1Click:Connect(function()
assets = Players:GetCharacterAppearanceInfoAsync(player.UserId)
end)
-- outside the button script
local assets = assets = Players:GetCharacterAppearanceInfoAsync(player.UserId)
pcall(function()
for _,v in pairs(assets.assets) do
for a, i in pairs(v) do
if type(i) == "string" then
name = i
end
if type(i) == "number" then
imageid = "https://www.roblox.com/asset-thumbnail/image?assetId="..i.."&width=420&height=420&format=png"
end
end
setGrid(imageid, tostring(name))
end
end)
My setGrid function is
function setGrid(imgid, labeltext)
local newGrid = template:Clone()
newGrid.Parent = maincontent
newGrid.Visible = true
newGrid:FindFirstChild("ImageLabel").Image = imgid
newGrid:FindFirstChild("TextLabel").Text = labeltext
end
Now, my second problem is, I am trying to get the button to remove the asset when clicked, since my setGrid
is a function which clones a template and such, I don’t know how to get the asset from that previous script, which is an issue since I want to get the asset to then be able to send an event to the server saying remove this please.
I’ve tried looking online for ways to fix it but can’t seem to find any, and I genuinely don’t know how to make it so I could get the asset any other way.