I was trying to print the names of the models in my set that I have by using GetUserSets method but I keep getting a error saying:
Workspace.Script:8: attempt to index global 'Model' (a nil value)
Why is it showing vairble Model as nil?
InsertService = game:GetService("InsertService") UserSets = InsertService:GetUserSets(1077607) Set = UserSets[1] -- Think of this like a tablet Set 1 = 1 Set 2 = 2 and so on SetId= Set.AssetSetId Collection = InsertService:GetCollection(SetId) for i = 1,10 do Model = Collection[i] AssestId = Model.AssestId print(AssestId.Name) end
So, to begin - trust Lua. It is nil
. You can see this yourself if you print
ed Model
. You'd also see something useful, something like this:
1203523 10358234 1203481 nil Workspace.Script:8: attempt to index global 'Model' (a nil value)
The reason is probably that your result, Collection
is a list fewer than 10
things in it. But, you ask for all the way up to Collection[i]
. Asking for an index which isn't in a table will result in nil
.
Instead, go up to the length of the table:
for i = 1, #Collection do
Locked by adark, SanityMan, and TheMyrco
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?