Lerping not working as intended

well i don’t exactly know what is making this to happen but can someone help me?

script:

Trigger.TouchEnded:Connect(function()
	for i = 0,1,.01 do
		wait()
		Door.CFrame = Door.CFrame:Lerp(ClosedPos.CFrame, i)
	end
end)

Video:

(sorry for bad quality but i had to make it bad so it will upload

you dont need the i to be here, the i is the time variable for the lerp

replace it with a number like ‘0.2’ (that fits the best here)

i replaced it. but the problem is still here

I think the issue you’re facing here is the fact that TouchEnded can fire multiple times at once, I recommend adding a debounce

still nothing here is the code:

Trigger.TouchEnded:Connect(function()
	if debounce == false then
		debounce = true
		for i = 0,1,.01 do
			wait()
			Door.CFrame = Door.CFrame:Lerp(ClosedPos.CFrame, 0.2)
		end
		debounce = false
	end
end)

Another problem with the code is that it’s always lerping between the current position and the end position.
(EDIT: I did not notice that this was what you intended, sorry)
So at first the door goes to 0.1 of the way to the end. Then it goes to 0.2 of the way between 0.1 of the way and the end, not to 0.2 of the way to the end.
Lerp between the start position and end position, not the current position and end position.

Trigger.TouchEnded:Connect(function()
	if debounce == false then
		debounce = true
		local OpenPos = Door.CFrame
		for i = 0,1,.01 do
			wait()
			Door.CFrame = OpenPos:Lerp(ClosedPos.CFrame, i) -- also replaced 0.2 with i
		end
		debounce = false
	end
end)
2 Likes

it works! but it’s very slow. Do you know how to make it faster?

nevermind figured it out myself