Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[UNANSWERED] Retaining model rotation when moving via primary cframe?

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)))

1 comment

0

You should use SetPrimaryPartCFrame

1 answer

Okay, What your doing is rotating every single part in the model, on its own axis. Roblox came up with this thing called,

SetPrimaryPartCFrame()

Wiki Link

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.

9 comments

0

what line i will set that in|??

0

What ever line sets the CFrame of the part...

0

It doesn't work when i rotate it, the model disappear from the map

0

Are you using math.rad() if your rotating by degres

0

yes i am look at the script

0

Doesn';t work rotateMod(_G.target:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,math.rad(10),0)))

0

@npott13 This is the answer, if not working on your script, you need to fix your script. Make sure your model has a PrimaryPart.

0

@superalp1111 it has primarypart, it rotates but just too far even i set the degree to 10 or 20 it rotates really wide like disappearing from the map.

0

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)))

This discussion is preserved as it was. New answers, comments, and votes are closed.