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

Sliding door doesn't always close. How do I fix this?

Asked by 3 years ago

Closes Sometimes but not Always unless you spam it a lot

Here is my script:

local TweenService = game:GetService("TweenService")

local model = script.Parent
local leftDoor = model.Doors.LeftDoor
local rightDoor = model.Doors.RightDoor
local prompt = model.Frame.Upper.Attachment.ProximityPrompt

local tweenInfo = TweenInfo.new(1)

local leftGoalOpen = {}
local leftGoalClose = {}
leftGoalOpen.CFrame = leftDoor.CFrame * CFrame.new(-leftDoor.Size.X*1.1, 0, 0)
leftGoalClose.CFrame = leftDoor.CFrame
local leftTweenOpen = TweenService:Create(leftDoor, tweenInfo, leftGoalOpen)
local leftTweenClose = TweenService:Create(leftDoor, tweenInfo, leftGoalClose)

local rightGoalOpen = {}
local rightGoalClose = {}
rightGoalOpen.CFrame = rightDoor.CFrame * CFrame.new(rightDoor.Size.X*1.1, 0, 0)
rightGoalClose.CFrame = rightDoor.CFrame
local rightTweenOpen = TweenService:Create(rightDoor, tweenInfo, rightGoalOpen)
local rightTweenClose = TweenService:Create(rightDoor, tweenInfo, rightGoalClose)

prompt.Triggered:Connect(function()
    if prompt.ActionText == "Close" then
        leftTweenClose:Play()
        rightTweenClose:Play()
        prompt.ActionText = "Open"
    else
        leftTweenOpen:Play()
        rightTweenOpen:Play()
        prompt.ActionText = "Close"
    end
    leftTweenOpen:Play()
    rightTweenOpen:Play()
end)

Answer this question