I went through multiple renditions of the code before I settled on that pattern, so there are some unnecessary vestiges, and the maxRotation variable which was supposed to be configurable really isn’t.
I was more interested in finding a cleaner way to rotate the CFrame in the pattern of a figure eight than anything else. How would you guys do that?
You can find the code and the model download link on the help thread:
I have seen your script and have some ways on how to improve it.
First capitalize the :connect to :Connect. Un-capitalized is old and deprecated so don’t use it.
Second change the tick() to os.clock(). tick() is deprecated old and not as good.
Here’s a finalized script:
local RunService = game:GetService("RunService")
local Rotator = script.Parent
local Origin = Rotator.CFrame
local Dampener = 5 -- higher numbers result in lower speed
local MaxRotation = 180
local x,y = 0,0
local function Lerp(a,b,t)
return (1-t)*a + t*b
local t = (os.clock()/Dampener)%2
x,y = Lerp(-1,1,t),Lerp(1,-1,t)
Rotator.CFrame = Origin*CFrame.Angles(math.rad(x*MaxRotation),math.rad(y*MaxRotation),0)