xbox789
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1947 |
|
|
| 26 Jun 2014 02:33 PM |
So I have a script that allows dynamic loading of objects. I'm currently working on the rotation of the parts inside the model. Problem is, i'm getting the error "Workspace.Script:9: attempt to get length of local 'childr' (a userdata value)". Is there something i'm doing wrong?
children = Workspace:GetChildren() storage = game:GetService("ServerStorage") apartments = {storage.Apartment1} function clicked(ogmodel, center, new) cfr = ogmodel:GetModelCFrame() if ogmodel.Door.CanCollide == true then function rotation(center, new, model, childr) -- rotating the apartment based on the rotation of the base apartment. print(model) for i=1, #childr do if childr[i]:IsA("BasePart") then print(new) childr[i].CFrame = new:toWorldSpace(center:toObjectSpace(childr[i].CFrame)) end if childr[i]:IsA("Model") then rotation(objects,center,new,childr[i]) end end end ogmodel:Destroy() modela = storage.Apartment1:Clone() modela.Parent = game.Workspace modela:MoveTo(cfr.p) modela:TranslateBy(Vector3.new(cfr.x-modela:GetModelCFrame().x,cfr.y - modela:GetModelCFrame().y,cfr.z - modela:GetModelCFrame().z)) for j=1, #modela:GetChildren() do print(modela:GetChildren()[j].Name) end rotation(center,new,modela,modela:GetChildren()) modela.Door.CanCollide = false modela.Door.Transparency = 1 end end while wait() do for i=1, #children do if children[i].Name == "Apartment" and children[i].ClassName == "Model" then center = children[i]:GetModelCFrame() script.Parent = children[i].Door.ClickDetector script.Parent.MouseClick:connect(function(script) clicked(children[i], center, center * CFrame.Angles(0,math.rad(children[i].Part.Rotation.Y),0)) end) end end end |
|
|
| Report Abuse |
|
|
xbox789
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1947 |
|
|
| 26 Jun 2014 02:37 PM |
| Forgot to say, the scripts parent travels into every part named door in every apartment, so I don't have to copy and paste this script into every apartment. |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2014 02:38 PM |
You never defined "childr."
I'm assuming your first line is supposed to be:
childr = game.Workspace:GetChildren()
not
children = game.Workspace:GetChildren() |
|
|
| Report Abuse |
|
|
xbox789
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1947 |
|
|
| 26 Jun 2014 02:40 PM |
| Children is used at the bottom, children and childr are different. Children is all of the children of Workspace. Childr is all of the children of the apartment model. |
|
|
| Report Abuse |
|
|
xbox789
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1947 |
|
| |
|
xbox789
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1947 |
|
|
| 26 Jun 2014 03:14 PM |
| Fixed it, was a problem with the function detecting if the object was a model. |
|
|
| Report Abuse |
|
|