So I know this code is disgusting to look at, but it made the elevator look smooth when it goes up and down, this also includes smooth door opening and closing. However when players go on it sometimes they teleport through it or the elevator jitters up/down. Any ideas on fixing this? (I am using the tweenservice for the movement of the elevator
local tweenService = game:GetService("TweenService")
local infoT = TweenInfo.new()
local f = false
local function teleportModel(model, CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, infoT, {Value = CF})
tween:Play()
tween.Completed:Connect(function()
CFrameValue:Destroy()
f = true
end)
end
local info = TweenInfo.new(15, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local function tweenModel(model, CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()
tween.Completed:Connect(function()
CFrameValue:Destroy()
f = true
end)
end
local config = script.Parent.Configuration
local lift = script.Parent.Lift
local topDoor = script.Parent.Doors.TopDoors
local botDoor = script.Parent.Doors.BottomDoors
local ts = game:GetService("TweenService")
-- Translation Info
local times = 130
local incO = 0.1
local speed = incO / 10
local drag = incO / times
local inc = 0 -- Ignore this
-- Main Elevator Info
local waitT = 10 -- Lift wait time
local startP = "bottom" -- Either "top" or "bottom"
if startP == "top" then
inc = incO
local lB = botDoor.LowerBottom
local tB = botDoor.UpperBottom
local lBz = topDoor.LowerBottom
local tBz = topDoor.UpperBottom
teleportModel(script.Parent.Lift, script.Parent.targetT.CFrame)
for i=0,times,1 do
inc = inc - drag
lB:TranslateBy(Vector3.new(0, inc, 0))
tB:TranslateBy(Vector3.new(0, -inc, 0))
end
inc = incO
for i=0,times,1 do
inc = inc - drag
lBz:TranslateBy(Vector3.new(0, -inc, 0))
tBz:TranslateBy(Vector3.new(0, inc, 0))
end
elseif startP == "bottom" then
inc = incO
local lB = topDoor.LowerTop
local tB = topDoor.UpperTop
local lBz = botDoor.LowerBottom
local tBz = botDoor.UpperBottom
teleportModel(script.Parent.Lift, script.Parent.targetB.CFrame)
for i=0,times,1 do
inc = inc - drag
lB:TranslateBy(Vector3.new(0, inc, 0))
tB:TranslateBy(Vector3.new(0, -inc, 0))
end
inc = incO
for i=0,times,1 do
inc = inc - drag
lBz:TranslateBy(Vector3.new(0, -inc, 0))
tBz:TranslateBy(Vector3.new(0, inc, 0))
end
end
function openDoorb()
inc = incO
local lB = botDoor.LowerBottom
local tB = botDoor.UpperBottom
for i=0,times,1 do
wait(speed)
inc = inc - drag
lB:TranslateBy(Vector3.new(0, -inc, 0))
tB:TranslateBy(Vector3.new(0, inc, 0))
end
end
function closeDoorb()
inc = incO
local lB = botDoor.LowerBottom
local tB = botDoor.UpperBottom
for i=0,times,1 do
wait(speed)
inc = inc - drag
lB:TranslateBy(Vector3.new(0, inc, 0))
tB:TranslateBy(Vector3.new(0, -inc, 0))
end
end
function openDoort()
inc = incO
local lB = topDoor.LowerTop
local tB = topDoor.UpperTop
for i=0,times,1 do
wait(speed)
inc = inc - drag
lB:TranslateBy(Vector3.new(0, -inc, 0))
tB:TranslateBy(Vector3.new(0, inc, 0))
end
end
function closeDoort()
inc = incO
local lB = topDoor.LowerTop
local tB = topDoor.UpperTop
for i=0,times,1 do
wait(speed)
inc = inc - drag
lB:TranslateBy(Vector3.new(0, inc, 0))
tB:TranslateBy(Vector3.new(0, -inc, 0))
end
end
function liftU()
f = false
local t = tweenModel(script.Parent.Lift, script.Parent.targetT.CFrame)
repeat
wait()
until f == true
end
function liftD()
f = false
tweenModel(script.Parent.Lift, script.Parent.targetB.CFrame)
repeat
wait()
until f == true
end
while wait() do
if startP == "bottom" then
wait(waitT)
closeDoorb()
liftU()
openDoort()
wait(waitT)
closeDoort()
liftD()
openDoorb()
else
wait(waitT)
closeDoort()
liftD()
openDoorb()
wait(waitT)
closeDoorb()
liftU()
openDoort()
end
end

2 comments
The debounce was renamed to f
"f" is a local for false.