Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with variables? [closed]

Asked by 9 years ago

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

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?

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

So, to begin - trust Lua. It is nil. You can see this yourself if you printed 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
1
Thanks for the help,but now it won't print any of the names why? kevinnight45 550 — 9y
2
`assetId` is a number, so `assetId.anything` doesn't make sense. To get the name, use `model.name` not `assetId.Name` BlueTaslem 18071 — 9y
1
As an addenum, kevinnight, I suggest looking up generic for loops, which are designed for iterating through tables, like you do here. adark 5487 — 9y
Ad