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

Why doesn't the tween for my sliding door work?

Asked by 4 years ago

I'm trying to make a sliding door that will either open or close when I click a button. It will open, if I only have the open tweenservice set into place, if I add the close one, it all stops working. Here is my code.

open = true

local TweenService = game:GetService("TweenService")

local door1 = script.Parent.door1


local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local door1Open = Vector3.new(-101.746, 5.52, 17.11)
local door1Close = Vector3.new(-108.172, 5.52, 17.11)

local Open1 = TweenService:Create(door1, tweenInfo, door1Open)
local Close1 = TweenService:Create(door1, tweenInfo, door1Close)

script.Parent.button.ClickDetector.MouseClick:Connect(function()
    if open == true then
        Close1:Play()
        wait(2)
        open = false
    else
        Open1:Play()
        wait(2)
        open = true
    end
end)

If I only have open or close, it works, if I add another one, it all stops working. Help is appreciated.

1 answer

Log in to vote
0
Answered by 4 years ago

The third argument to the Create() function is a table of properties. The key is the property you want to edit, and the value is the end result of the tween.

In your case you can adjust the script like so (lines 13 & 14):

local Open1 = TweenService:Create(door1, tweenInfo, {Position = door1Open})
local Close1 = TweenService:Create(door1, tweenInfo, {Position = door1Close})
Ad

Answer this question