Hello,

So this script rotates a model. I want to know how can I alter it so that I can tell it when to stop. I want it to rotate the model so it flips it to the other direction.

Thanks,

Anthony

-- Just put this script in a model to make it rotate
local speed = 700 -- the speed it spins at, change this to how fast you want it to spin

local orig = script.Parent
local rotation = 0
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/500)
	if(rotation>360)then rotation = 0 end
	ModelCFrame(orig,cf*CFrame.Angles(0,math.rad(rotation),0))
end

1 comment

0

On link 6, try "local cf = orig:GetPrimaryPartCFrame()"