Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a realistic and smooth elevator using PrimaryPartCFrame?

Asked by 3 years ago
Edited 3 years ago

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:

01local TweenService = game:GetService("TweenService")
02 
03game.ReplicatedStorage.GoUp.OnServerEvent:Connect(function()
04    local Time = time()
05    local Total = 5
06    local Model = workspace.ElevatorWorking
07    local Start = Model:GetPrimaryPartCFrame()
08    local End = workspace.clone1.B.CFrame
09    while time() - Time <= Total do
10        local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
11        local CFrame2 = Start:Lerp(End,TI)
12        Model:SetPrimaryPartCFrame(CFrame2)
13        wait()
14    end
15end)
View all 29 lines...

Client:

1local btnA = script.Parent.A
2local btnB = script.Parent.B
3 
4btnA.MouseButton1Up:Connect(function()
5    game.ReplicatedStorage.GoDown:FireServer()
6end)
7btnB.MouseButton1Up:Connect(function()
8    game.ReplicatedStorage.GoUp:FireServer()
9end)

(A is floor 1 while B is floor 2)

Thank you!

1 answer

Log in to vote
1
Answered by
NEILASc 84
3 years ago

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.

0
thx T3_MasterGamer 2189 — 3y
Ad

Answer this question