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

Why is my iterator loop complaining about my calling of userdata?

Asked by
P100D 590 Moderation Voter
9 years ago

This is my script. I tried it without the pairs() command, still didn't work.

for i, v in pairs(model) do
    local script = script1:clone()
    script.Parent = v
end
0
What is the error? Where have you declared 'script'? Where have you declared 'model'? Is 'model' an actual model? If so, you need to use :GetChildren() DigitalVeer 1473 — 9y
0
Also, "script" by default refers to the script the code is running in. Don't ever use "script" to name a variable Validark 1580 — 9y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Based on the context of your script, and the error message, i'll give my answer.. this is an assumption though.


Your Problem

You're using model as the arguments for your pairs function on line 1. If 'model' is an actual model, then you're probably getting an error like;

Expected table, got userdata

.. because the pairs function takes in arguments of whatever table you're iterating through.. a model instance is not a table, it's a userdata.


How To Fix

You need to use the GetChildren method. The GetChildren method returns a table full of all the direct children of the specified object.


Code

for i, v in pairs(model:GetChildren()) do --GetChildren
    script1:Clone().Parent = v
end
Ad

Answer this question