Need help Lerping.s

Hello devs, recently i tried replicating a cage roll gambling machine that i’ve found on a game. The problem is the slowing at the end of the rotations.

External Media

I tried my best for an hour or more but didn’t succeed. Here’s my code:

local start = PartToTween.CFrame
local target = PartToTween.CFrame * CFrame.Angles(math.rad(180), 0, 0)

task.spawn(function()
		for rotation = 1, 10 do
			for t = 0, 1, .035 do
				PartToTween.CFrame = start:Lerp(target, t) * CFrame.Angles(math.rad(90), 0, 0)
				task.wait()
			end
		end
		local newStart = PartToTween.CFrame
		local newTarget = PartToTween.CFrame * CFrame.Angles(math.rad(180),0,0)
		local factor = 1
		
		for t = 0, 1, 0.035 do
			factor =- .035
			PartToTween.CFrame = newStart:Lerp(newTarget, factor)
			task.wait()
		end
	end)

The 2nd for t = 0, 1, .0035 do loop doesn’t slow it properly, it stops instantly and i need help please.
And here’s the result of this code:

2 Likes

you could tween it at the end to make it slowly reset to its position

1 Like
		for rotation = 1, 10 do
			for t = 0, 1, .035 do
				PartToTween.CFrame = start:Lerp(target, t) * CFrame.Angles(math.rad(90), 0, 0)
				task.wait()
			end
		end

		local rotations = 10
		local spinTime = 5
		local initialCF = PartToTween.CFrame
		local startTime = os.clock()
		while true do
			local percent = math.clamp((os.clock() - startTime)/spinTime, 0, 1)
			local easedPercent = percent ^ .5
			PartToTween.CFrame = initialCF * CFrame.Angles(math.pi*2*rotations*easedPercent,0,0)
			if percent >= 1 then
				break
			end
			task.wait()
		end

Untested

1 Like