Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I reset a model's original rotation after it randomly rotating around?

Asked by
Nidoxs 190
8 years ago

How do I reset a model's original rotation after it randomly rotating around? I want the model's rotation to be 0,0,0 when I am done with the animation of the model.

local speed = 40

local orig = script.Parent
local rotation = math.random(-360,360)
local cf = orig:GetModelCFrame()


function ModelCFrame(Model,Frame)
    local search,MidFrame,list = nil,Model:GetModelCFrame(),{}
    search=function(a)
        for n,o in pairs(a:GetChildren())do
            if(o:IsA("BasePart"))then
                table.insert(list,o)
            end
            search(o)
        end
    end
    search(Model)
    for n,o in pairs(list)do 
        o.CFrame=Frame*MidFrame:toObjectSpace(o.CFrame)
    end 
end


while(wait())do
    rotation = rotation+(speed/5)
    if(rotation>360)then rotation = 0 end
    ModelCFrame(orig,cf*CFrame.Angles(math.rad(rotation),math.rad(rotation),math.rad(rotation)))
end
3
Have you tried ModelCFrame(orig, cf)? cf should contain the original rotation. Lacryma 548 — 8y

1 answer

Log in to vote
0
Answered by
xuefei123 214 Moderation Voter
8 years ago

Maybe save the rotation in a variable and after rotating it, put it back to the original variable rotation

Ad

Answer this question