How can i retain the model rotation when moving model using SetPrimaryCFrame?
Because whenever i rotate the model by any degree and move it, the model don't retain the rotation i set. This is a problem i'm currently have with my model dragging script...
The rotation script.
mouse.KeyDown:connect(function (key) -- Safe rotation pcall (function() function rotateMod(mod,rotation) if key == "r" and _G.target:FindFirstChild("CanRotate") then local center = mod:GetModelCFrame() local parts ={} local function scan(parent) for _,obj in pairs(parent:GetChildren()) do if (obj:IsA("BasePart")) then table.insert(parts,obj) end scan(obj) end end scan(mod) for _,part in pairs(parts) do part.CFrame = (center*rotation*(center:inverse()*part.CFrame)) end end end rotateMod(_G.target,CFrame.Angles(0,math.rad(10),0)) end) end)
****UPDATE****
Abstract_Life answer doesn't work it shows error . This is the output, i am so stupid i forgot i had pcall function on the rotation script that's why it wasn't sending error. But i removed it and this what it says "Players.Player1.Backpack.LocalScript:8: attempt to index local 'mod' (a nil value)" , This is the error when i replaced the line 24 with rotateMod(_G.target:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,math.rad(10),0)))
Okay, What your doing is rotating every single part in the model, on its own axis. Roblox came up with this thing called,
SetPrimaryPartCFrame()
You can use this by doing so;
Model:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,0,0))
The only issue with this is, You need to set a primary part under the models property tab. When you set the primary part, remember that the whole model will orientate(rotate) around the center of this primary part. I usually create a brick, make sure its length's are the same, and set the center of it as the model.