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

How to make a realistic and smooth elevator using PrimaryPartCFrame?

Hello! I'm trying to make a moving elevator using for my game (both lobby and game) and I found this script in a question. I tried it myself and it did work, but when I test it out I keep glitching out of the map, the elevator is glitching, going up and down for no reason at all, and randomly teleports up and down while moving. I'm finding a solution, or better, a different code that will look good in my work. Here's the code:

Server:

local TweenService = game:GetService("TweenService")

game.ReplicatedStorage.GoUp.OnServerEvent:Connect(function()
	local Time = time()
	local Total = 5
	local Model = workspace.ElevatorWorking
	local Start = Model:GetPrimaryPartCFrame()
	local End = workspace.clone1.B.CFrame
	while time() - Time <= Total do
		local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
		local CFrame2 = Start:Lerp(End,TI)
		Model:SetPrimaryPartCFrame(CFrame2)
		wait()
	end
end)

game.ReplicatedStorage.GoUp.OnServerEvent:Connect(function()
	local Time = time()
	local Total = 5
	local Model = workspace.ElevatorWorking
	local Start = Model:GetPrimaryPartCFrame()
	local End = workspace.clone1.A.CFrame
	while time() - Time <= Total do
		local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
		local CFrame2 = Start:Lerp(End,TI)
		Model:SetPrimaryPartCFrame(CFrame2)
		wait()
	end
end)

Client:

local btnA = script.Parent.A
local btnB = script.Parent.B

btnA.MouseButton1Up:Connect(function()
	game.ReplicatedStorage.GoDown:FireServer()
end)
btnB.MouseButton1Up:Connect(function()
	game.ReplicatedStorage.GoUp:FireServer()
end)

(A is floor 1 while B is floor 2)

Thank you!

1 answer

✓ Accepted answer

the lerp function only takes 2 inputs. one of them is time (0 to 1) and the end position or cframe or value of anything.

example: your start position is 0,0,0 and end position is 0,10,0. and you use the lerp function and the time is set to 0.5. the current position would be 0,5,0

and i reccommend using the api service about tweenservice.

1 comment

0

thx

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