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

Smooth Elevator, issue with jittering and player phasing. Fixes?

Asked by 5 years ago

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

1 answer

Log in to vote
0
Answered by
Stycon 30
5 years ago

Well, you could make the elevator itself not colliding and have separate parts with separate movements, and make these other parts invisible. The separate parts should likely be a simple hallow block. I also did not see a check for debounce anywhere, but I was just scanning. If you have the debounce and this problem is still happening, try the simple collision block with the other cosmetics of the elevator with no collisions. If even that does not work, just make the illusion of the elevator going up. What I mean is that you would have the player walkspeed and jumppower set to zero, teleport the player to the desired floor (teleport with Z coordinates only), and set the jumppower and walkspeed back to normal.

0
The debounce was renamed to f User#16405 0 — 5y
0
"f" is a local for false. Stycon 30 — 5y
Ad

Answer this question