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
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
Based on the context of your script, and the error message, i'll give my answer.. this is an assumption though.
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.
You need to use the GetChildren method. The GetChildren method returns a table full of all the direct children of the specified object.
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.
2 comments
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()
Also, "script" by default refers to the script the code is running in. Don't ever use "script" to name a variable