Asset always = nil?

No matter what I do, asset is always nil. Any help?

Server Script
local Items = require(game:GetService("ReplicatedStorage").Modules.Items)

Inventory = {
   ["Default"] = {Info = Items["Default"]},
},	
Client
for i, v in pairs(Data.Inventory) do
	print(v.Info.Asset)
	InvGui.Information.Icon.Title.Text = i
	InvGui.Information.Icon.ImageLabel.Image = "rbxassetid://" .. v.Info.Asset
end
Items Module
return {
	["Default"] = {Skin = 111867655, Asset = 1258605917, Rarity = "Default", Colour = 97, 99, 10},
	["QuackMystic"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Mystical", Colour = 255, 0, 191},
	["QuackLegendary"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Legendary", Colour = 255, 176, 0},	
	["QuackRare"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Rare", Colour = 255, 89, 89},
	["QuackUncommon"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Uncommon", Colour = 167, 94, 155},
	["QuackCommon"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Common", Colour = 128, 187, 219},
	["QuackUnique"] = {Skin = 1258587889, Asset = 1258713424, Rarity = "Unique", Colour = 58, 125, 21},	

	["None"] = {Skin = 0, Asset = 0, Rarity = "Nothing", Colour = 97, 99, 10},	
}

Error is: attempt to concatenate field 'Asset' (a nil value)

1 Like

What code are you using to send the Inventory table to the client?

game:GetService("ReplicatedStorage").Events.GetData:FireClient(Plr, DataTable[Plr])

This is an easy one. You wrote this at the end of your tables:

(...) , Colour = 58, 125, 21},

This does not instantiate the table in the way you think it does. Color will refer to 58, and 125 and 21 will be set numerical indices 1 and 2 respectively.

When you send this table through remotes, the remotes will cut off the string indices as it interprets your table as arrays due to the numerical indices. This is a caveat of remotes and it’s honestly bad that it doesn’t throw a warning for this.

7 Likes

So I should use this?

(...) , Colour = {58, 125, 21}},

Yes.

Or just wrap the values in Roblox’s Color3 type, which Bindables/Remotes can handle.

(I tested Bindables at least)

1 Like

No, that’s not what you should do. If you’re going for a RGB Color, you want to do this:

(...), Color = Color3.fromRGB(58, 125, 21)},

You can apply that to a GUI element after.

Element.BackgroundColor3 = whatever.Color

You can’t store Color3 values in DataStores, you will get the 104: Dictionary error.

If you want to store userdata values like Color3 into JSON for datastores, this can help: https://www.roblox.com/library/1005802894/JSON-with-Userdata-Support

Or just store R/G/B values independently, which is what the module does, but generalized for lots of userdata types.