for _, assets in pairs(PlayersHumanoid.assets) do
for i, asset in pairs(assets) do
if type(asset) == 'table' then
for _, assetType in pairs(asset) do
if assetType == 'Face' then
print(asset.name)
end
end
end
end
end
If the asset table was like
assets = {
{
id = 28999228,
assetType = {
name = "Face",
id = 18
},
name = "Joyous Surprise"
},
)
And I want the print() to print ‘Joyous Surprise’, but it’s printing ‘Face’ instead. Any ideas to clean this up and get it working properly??
for _, assets in pairs(PlayersHumanoid.assets) do
for i, asset in pairs(assets) do
if type(asset) == 'table' then
if assetType == 'Face' then
print(asset.name)
end
end
end
end
And I’d have no way of knowing what ‘assetType’ actually is
Rezault is on the right lines, but a further change has to be made in order for it to work. In your initial code, the line for _, assetType in pairs(asset) do is actually iterating through the keys and values of an asset. So that for loop can be removed.
When it’s in a dictionary structure, you can index it by the keys of the assets. This means to get the assetType of an asset you can simply use asset.assetType.name. Currently, in your revised code with the change implemented you’re comparing an undefined variable with ‘Face’.
With this change reflected in your code you get:
for _, assets in pairs(PlayersHumanoid.assets) do
for i, asset in pairs(assets) do
if type(asset) == 'table' then
if asset.assetType.name == 'Face' then
print(asset.name)
end
end
end
end
[attempt to index field ‘assetType’ (a nil value)]
for _, assets in pairs(PlayersAppearance.assets) do
for i, asset in pairs(assets) do
if type(asset) == 'table' then
if asset.assetType.name == 'Face' then --Error here
print(asset.name)
end
end
end
end
local PlayersAppearance = Players:GetCharacterAppearanceInfoAsync(Player.UserId)
for _, assets in pairs(PlayersAppearance.assets) do
for i, asset in pairs(assets) do
if type(asset) == 'table' then
if asset.assetType.name == 'Face' then
print(asset.name)
end
end
end
end
Doesn’t really matter cause just found out freaking InsertService doesn’t work from the client anyway
My bad, I just realised you’re iterating through PlayersAppearance.assets. The following iterating is unnecessary as there’s no need to iterate through each item in the assets dictionary.
for _, asset in pairs(PlayersAppearance.assets) do
if type(asset) == 'table' then
if asset.assetType.name == 'Face' then
print(asset.name)
end
end
end
As for your problem requiring InsertService not working from the client, would you not be able to just do all this work on the server and then pass the assets to the client after being inserted?
And ye that’s probably what I will do. Just frustrating, as it will require remoteevents and stuff to be called and items to be stored somewhere temporarily, etc. was hoping for just a simple insert onto the model bam and be done