Can someone explain why this elevator shakes and how to fix it for a smoother ride? Thanks.
Here are the scripts.
Client script:
local ts = game:GetService("TweenService")
local topDoorStartPos = Vector3.new(0.811, 35.367, -435.086)
local topDoorEndPos = Vector3.new(0.811, 22.526, -435.086)
local bottomDoorStartPos = Vector3.new(0.811, -639.249, -435.086)
local bottomDoorEndPos = Vector3.new(0.811, -652.458, -435.086)
local elevatorStartPos = script.Parent:WaitForChild("ElevatorUpPos").CFrame
local elevatorEndPos = script.Parent:WaitForChild("ElevatorDownPos").CFrame
local elevatorMiddlePos = script.Parent:WaitForChild("ElevatorMiddlePos").CFrame
local elevator = script.Parent:WaitForChild("Elevator")
local topDoor = script.Parent:WaitForChild("TopDoor")
local bottomDoor = script.Parent:WaitForChild("BottomDoor")
local detector = elevator:WaitForChild("Detector")
local waitUpTime = 30
local waitDownTime = 30
local glassCloseTime = 2
local glassOpenTime = 2.75
local elevatorDownTime = 20
local elevatorUpTime = 20
local state = script.Parent:WaitForChild("State")
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local function tweenModel(model, cframe, time)
local cframeValue = Instance.new("CFrameValue")
cframeValue.Value = model:GetPrimaryPartCFrame()
cframeValue:GetPropertyChangedSignal("Value"):connect(function()
model:SetPrimaryPartCFrame(cframeValue.Value)
end)
local info = TweenInfo.new(time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tween = ts:Create(cframeValue, info, {Value = cframe})
tween:Play()
tween.Completed:connect(function()
cframeValue:Destroy()
end)
end
local function tweenModel2(model, cframe, time)
local cframeValue = Instance.new("CFrameValue")
cframeValue.Value = model:GetPrimaryPartCFrame()
cframeValue:GetPropertyChangedSignal("Value"):connect(function()
model:SetPrimaryPartCFrame(cframeValue.Value)
end)
local info = TweenInfo.new(time, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local tween = ts:Create(cframeValue, info, {Value = cframe})
tween:Play()
tween.Completed:connect(function()
cframeValue:Destroy()
end)
end
state:GetPropertyChangedSignal("Value"):Connect(function()
if state.Value == "GlassUpClosing" then
topDoor.CloseDoor:Play()
ts:Create(topDoor, TweenInfo.new(glassCloseTime), {Position = topDoorEndPos}):Play()
end
if state.Value == "GoingDown" then
--for i, part in next, GetTouchingParts(detector) do
-- if part.Parent:FindFirstChild("Humanoid") then
-- part.Parent.Archivable = true
-- part.Parent.Humanoid.WalkSpeed = 0
-- part.Parent.Parent = elevator.Players
-- part.Parent.HumanoidRootPart.Anchored = true
-- end
--end
tweenModel2(elevator, elevatorMiddlePos, elevatorDownTime / 2)
task.wait(elevatorDownTime / 2)
tweenModel(elevator, elevatorEndPos, elevatorDownTime / 2)
end
if state.Value == "GlassDownOpening" then
bottomDoor.OpenDoor:Play()
ts:Create(bottomDoor, TweenInfo.new(glassOpenTime), {Position = bottomDoorStartPos}):Play()
--for i, part in next, GetTouchingParts(detector) do
-- if part.Parent:FindFirstChild("Humanoid") then
-- part.Parent.Parent = workspace
-- part.Parent.HumanoidRootPart.Anchored = false
-- part.Parent.Humanoid.WalkSpeed = 16
-- part.Parent.Archivable = false
-- end
--end
end
if state.Value == "GlassDownClosing" then
bottomDoor.CloseDoor:Play()
ts:Create(bottomDoor, TweenInfo.new(glassCloseTime), {Position = bottomDoorEndPos}):Play()
end
if state.Value == "GoingUp" then
--for i, part in next, GetTouchingParts(detector) do
-- if part.Parent:FindFirstChild("Humanoid") then
-- part.Parent.Archivable = true
-- part.Parent.Humanoid.WalkSpeed = 0
-- part.Parent.Parent = elevator.Players
-- part.Parent.HumanoidRootPart.Anchored = true
-- end
--end
tweenModel2(elevator, elevatorMiddlePos, elevatorUpTime / 2)
task.wait(elevatorUpTime / 2)
tweenModel(elevator, elevatorStartPos, elevatorUpTime / 2)
end
if state.Value == "GlassUpOpening" then
topDoor.OpenDoor:Play()
ts:Create(topDoor, TweenInfo.new(glassOpenTime), {Position = topDoorStartPos}):Play()
--for i, part in next, GetTouchingParts(detector) do
-- if part.Parent:FindFirstChild("Humanoid") then
-- part.Parent.Parent = workspace
-- part.Parent.HumanoidRootPart.Anchored = false
-- part.Parent.Humanoid.WalkSpeed = 16
-- part.Parent.Archivable = false
-- end
--end
end
end)
Server script:
local waitUpTime = 30
local waitDownTime = 30
local glassCloseTime = 2
local glassOpenTime = 2.75
local elevatorDownTime = 20
local elevatorUpTime = 20
local state = script.Parent:WaitForChild("State")
local soundPart = script.Parent:WaitForChild("Elevator"):WaitForChild("SoundPart")
while true do
task.wait(waitUpTime)
state.Value = "GlassUpClosing"
task.wait(glassCloseTime)
task.wait(1)
soundPart.elestart:Play()
task.wait(1)
state.Value = "GoingDown"
soundPart.Elevator:Play()
task.wait(elevatorDownTime - 3)
soundPart.ArriveMainFacility:Play()
task.wait(2.8)
soundPart.Elevator:Stop()
soundPart.eleend:Play()
task.wait(0.2)
task.wait(2)
state.Value = "GlassDownOpening"
task.wait(glassOpenTime)
state.Value = "WaitingDown"
task.wait(waitDownTime)
state.Value = "GlassDownClosing"
task.wait(glassCloseTime)
task.wait(1)
soundPart.elestart:Play()
task.wait(1)
state.Value = "GoingUp"
soundPart.Elevator:Play()
task.wait(elevatorUpTime - 3)
soundPart.ArriveTopside:Play()
task.wait(2.8)
soundPart.Elevator:Stop()
soundPart.eleend:Play()
task.wait(0.2)
task.wait(2)
state.Value = "GlassUpOpening"
task.wait(glassOpenTime)
state.Value = "WaitingUp"
end