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:
01 | local TweenService = game:GetService( "TweenService" ) |
03 | game.ReplicatedStorage.GoUp.OnServerEvent:Connect( function () |
06 | local Model = workspace.ElevatorWorking |
07 | local Start = Model:GetPrimaryPartCFrame() |
08 | local End = workspace.clone 1. B.CFrame |
09 | while time() - Time < = Total do |
10 | local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In) |
11 | local CFrame 2 = Start:Lerp(End,TI) |
12 | Model:SetPrimaryPartCFrame(CFrame 2 ) |
17 | game.ReplicatedStorage.GoUp.OnServerEvent:Connect( function () |
20 | local Model = workspace.ElevatorWorking |
21 | local Start = Model:GetPrimaryPartCFrame() |
22 | local End = workspace.clone 1. A.CFrame |
23 | while time() - Time < = Total do |
24 | local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In) |
25 | local CFrame 2 = Start:Lerp(End,TI) |
26 | Model:SetPrimaryPartCFrame(CFrame 2 ) |
Client:
1 | local btnA = script.Parent.A |
2 | local btnB = script.Parent.B |
4 | btnA.MouseButton 1 Up:Connect( function () |
5 | game.ReplicatedStorage.GoDown:FireServer() |
7 | btnB.MouseButton 1 Up:Connect( function () |
8 | game.ReplicatedStorage.GoUp:FireServer() |
(A is floor 1 while B is floor 2)
Thank you!