Why does LoadAsset give me this error?

local success,MESSAGE = pcall (function()
			if dummy.Gender.Value == "Male" then
				Pants = game:GetService("InsertService"):LoadAsset(malepants[RandomInt(1,#malepants)]:GetChildren()[1])
				Shirt = game:GetService("InsertService"):LoadAsset(maleshirts[RandomInt(1,#maleshirts)]:GetChildren()[1])
			elseif dummy.Gender.Value == "Female" then
				Pants = game:GetService("InsertService"):LoadAsset(femalepants[RandomInt(1,#femalepants)]:GetChildren()[1])
				Shirt = game:GetService("InsertService"):LoadAsset(femaleshirts[RandomInt(1,#femaleshirts)]:GetChildren()[1])
			end
		end)

I receive this error when pcalling the above function. The tables female/male pants/shirts are all just like this:

local femaleshirts = {
     12345,
     67890
}

[ServerScriptService.Remote:530: attempt to index field '?' (a number value)]

Why is this happening and how can I stop it?

First thing I notice is you are using GetChildren on a table? Your post says that you are using a table; GetChildren is used for getting a list of all of the children in a Roblox object.

A few other questions I have, if I have missed anything in the original post:

  • Could you print out the contents of malepants and maleshirts (and same for female)
  • Could you print out the results of each RandomInt() call?
  • What does the function RandomInt() code look like?

It could also be helpful if you pointed out which line had the error, to make sure this just isn’t a table specific issue. One last protip would be to provide some more of your code, to make it easier to narrow down a potential fix.

1 Like

All of the lines with :LoadAsset() have issues.
RandomInt() is this:

function RandomInt(Min,Max)
     local Rand = Random.new()
     local Seed = Rand:NextInteger(Min,Max)
     return Seed
end

I do now notice the :GetChildren()[1] is placed improperly, however. Thanks.

To put in simply; You put your ) at the end, so you are calling :GetChildren() on the number from the table, which is not a function of a number, thus this error. (You called :GetChildren() on a number, the number was not expected)

To fix it, simply move your ) to the left:


local success,MESSAGE = pcall (function()
			if dummy.Gender.Value == "Male" then
				Pants = game:GetService("InsertService"):LoadAsset(malepants[RandomInt(1,#malepants)]):GetChildren()[1]
				Shirt = game:GetService("InsertService"):LoadAsset(maleshirts[RandomInt(1,#maleshirts)]):GetChildren()[1]
			elseif dummy.Gender.Value == "Female" then
				Pants = game:GetService("InsertService"):LoadAsset(femalepants[RandomInt(1,#femalepants)]):GetChildren()[1]
				Shirt = game:GetService("InsertService"):LoadAsset(femaleshirts[RandomInt(1,#femaleshirts)]):GetChildren()[1]
			end
		end)
1 Like