Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

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()

0

Also, "script" by default refers to the script the code is running in. Don't ever use "script" to name a variable

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.