I believe you mean that it will move the model above where you want it, because ROBLOX tends to do that. There are a few ways to do this. If you haven't already, read up on the CFrame wiki page. This will be invaluable in the script.
The first thing we'll need to do is use the method "GetModelCFrame". This gets the CFrame for the model. We'll set "modelCF" to it.
modelCF=car:GetModelCFrame()
Next, we have to figure out where we want to move it to. It should be a CFrame. We'll set "targetCFrame" to "pad.CFrame".
targetCFrame=pad.CFrame
Now we have to move the parts. The way you do this will vary depending on the model structure; this is the simple way. If you have submodels with parts in them, this method won't work, and you'll need recursion. We'll get the relative CFrame from modelCF to the part's CFrame, and then use that relation to move it to targetCFrame.
for i,v in pairs(car:children()) do
if v:IsA("BasePart") then
v.CFrame=targetCFrame:toWorldSpace(modelCF:toObjectSpace(v.CFrame))
end
end
This should complete the move. You can, of course, define a more general function:
function moveModel(model,targetCFrame)
for i,v in pairs(car:children()) do
if v:IsA("BasePart") then
v.CFrame=targetCFrame:toWorldSpace(model:GetModelCFrame():toObjectSpace(v.CFrame))
end
end
end
moveModel(car,pad.CFrame)
You could also use recursion to get the parts inside of submodels, as mentioned before.
1 comment
Will do Kenetec. But theoretically, since it is a Vector3, can I still move it inside of this object? Because usually moving a part into another part using Vector3 scripting is impossible.