Part not returning to original position after tween

The title says it all, this script is a serverscript in the door

local door1 = script.Parent
local TweenService = game:GetService("TweenService")
game.ReplicatedStorage.TweenDoors.Event:Connect(function()
local tweenInfo = TweenInfo.new(
	4, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
 
local tween = TweenService:Create(door1, tweenInfo, {Position = Vector3.new(-30.062, 10.339, -104.036)})
 
tween:Play()
end)

I used the dev hub script

1 Like

Is TweenDoors.Event a RemoteEvent? Also in the local tween variable everything is correct, however every time your event triggers it’s position is always set to Vector3.new(-30.062, 10.339, -104.036).

No ‘TweenDoors’ is a Bindable event

OK, so everytime your event fires you get to here

In the Position area your position is always set to the same Vector3, so if I’m correct it doesn’t tween back becuase it tweens to the same area. I could be wrong, I’m still relatively new to tweens.
EDIT: If that’s the case you could set an ‘if’ statement to your code and if the door is ‘open’ then essentially reverse the tween to it’s ‘closed’ position, then repeat.

Well it tries to tween back, but it never gets back to its original position

Try this,

local door1 = script.Parent
local TweenService = game:GetService("TweenService")
local opened = false

game.ReplicatedStorage.TweenDoors.Event:Connect(function()
    local tweenInfo = TweenInfo.new(
	    4, -- Time
	    Enum.EasingStyle.Linear, -- EasingStyle
	    Enum.EasingDirection.Out, -- EasingDirection
	    0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	    true, -- Reverses (tween will reverse once reaching it's goal)
	    0 -- DelayTime
    )
    if opened then -- true
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--closed position)})
        tween:Play()
        opened = false
    else
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--opened position)})
        tween:Play()
        opened = true
    end
end)
1 Like

Well now it isn’t tweening at all

then you have to put tween:Play() after and also put the appropriate positions in

Where would I put :Play()? (30 chars)

after the tween is defined

if opened then -- true
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--closed position)})
        tween:Play()
        opened = false
    else
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--opened position)})
        tween:Play()
        opened = true
    end
2 Likes

i also suggest also adding orientation to the goals list, or change from vector3 to CFrame

How would you add like a debounce for mouseclicks?

In this case, the variable “opened” can act as a debounce. Just add a wait based on the tween time before the variable is changed, so the door can be opened/closed only after the tweens are played

if opened then -- true
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--closed position)})
        tween:Play()
        wait(4)
        opened = false
    else
        local tween = TweenService:Create(door1,tweenInfo,{Position = Vector3.new(--opened position)})
        tween:Play()
        wait(4)
        opened = true
    end

Could you provide a gif of what happens? The “reverses” property in the TweenInfo should make it reverse back to its original position.

If it does tween back but doesn’t end up in the exact position you can always listen to the .Completed event on the tween and manually update the position yourself once it’s done.

1 Like