I'm trying to make a building with randomly generated rooms. It's coming along nicely, I'm using a script to clone in a random assortment of rooms from ReplicatedStorage and connect them. However, some of the rooms don't connect properly because they need to be rotated. However, I have no idea how to rotate a model via a script. I know that you use "MoveTo:" to move the model, however is there another thing that rotates a model? Btw, I don't currently have any code for rotating a model, because I literally don't know where to start. Help?
It's sadly more complicated than that (I think :0). You'd have to convert the children of the model into a table. Then Index the -PARTS- and rotate them accordingly. So we would first use the GetChildren()
function of the model. Then we would do an iteration, called for i,v in pairs("Table") do
. V would stand for the child of that model were on. So we must make sure that that child is a part. Then we would set the rotation/CFrame of that part manually. NOTE: this wont necessarily if there is a union or if it is a mesh. It would look something like this:
--before the code, you can always put this into a function rotation = Vector3.new(0,0,0) --the generic rotation value you want all the parts to have ModelChildren = game.Workspace.Model:GetChildren() --You can change " 'Model' to whatever you want" for i,v in pairs(ModelChildren) do if v:IsA("Part") and v ~=nil then --we find out if the object is a part or not and if it is other than "nil" v.Rotation = rotation --the generic rotation value you want it to be end
Now there are also other options for doing this (SetPrimaryPartCFrame). If you didn't like this answer, let someone else do it. Of coarse you can add stuff before or after this. It should be a good start :/. If you have any questions, please leave a comment. Otherwise, I have some links prepared for you below.
LINKS:
Tables: http://wiki.roblox.com/index.php?title=Table
Model API: http://wiki.roblox.com/index.php?title=API:Class/Model
Other options: http://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame