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

How would I use Lerp in this situation?

I'm very new to Lua and I'm trying to make a sliding door I have this so far:

local door = script.Parent
local new = script.parent.parent.Ending
local new2 = script.parent.parent.Start

script.parent.ClickDetector.MouseClick:Connect(function()
	door.CFrame = new.CFrame
	wait(5)
	door.CFrame = new2.CFrame
end)

But I want it to slowly go up instead of just appearing in that position. Any idea how I could do that?

5 comments

0

Why do you need to use Lerp() are you trying to create pseudo-Tweens?

0

Tweens?

0

TweenService is like creating a transition from Point A to Point B.

0

I see, how would I go about doing that?

0

I posted an answer of what you wanted.

1 answer

Right, CFrame:Lerp() has 2 parameters. The end goal (or point B), and the percentage. If you do a bit of math, you need to turn these percentages into decimals (or float). For example, if you want it to go 10% of the way, then you need to do 10 divided by 100, and it will give 0.1. If you want it to slowly go up (like a psuedo-Tween service), then I suggest using a for loop.

local door = script.Parent
local new = script.parent.parent.Ending
local new2 = script.parent.parent.Start

script.parent.ClickDetector.MouseClick:Connect(function()
	door.CFrame = new.CFrame
	for i = 0, 1, 0.01 do --If you know about for loops, the 1st is a start, then 2nd is the end, and the 3rd is the increment.
		wait()
		door.CFrame = CFrame:Lerp(new2.CFrame, i)
	end
end)

Keep it mind it lerps for both Position and Orientation (or Rotation). Lerp stands for Linear Interpolation, by the way. Edit: Changed some things.

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