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

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

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

1 comment

3

Have you tried ModelCFrame(orig, cf)? cf should contain the original rotation.

1 answer

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

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