generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: :GetChildren() problem

Previous Thread :: Next Thread 
xbox789 is not online. 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 is not online. 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
1MangoMan0 is not online. 1MangoMan0
Joined: 28 Sep 2010
Total Posts: 1596
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 is not online. 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 is not online. xbox789
Joined: 25 Aug 2008
Total Posts: 1947
26 Jun 2014 02:55 PM
Bump
Report Abuse
xbox789 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image