Tweening Position not working?

  1. What do you want to achieve?
    I would like for the door to open up, by tweening the vector3 position upwards.

  2. What is the issue?
    The issue is that it goes up fine and to the position I want it to go up to, but when it comes back down it goes to a random spot.

Here is the code directly a child of the part named Door

local TweenService = game:GetService("TweenService")

local isOpen = false
local debounce = false

local DoorInfo = TweenInfo.new(3)

local DoorOpenGoal = {}
DoorOpenGoal.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y + 5.9, script.Parent.Position.Z)

local DoorCloseGoal = {}
DoorCloseGoal.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y - 5.9, script.Parent.Position.Z)

local DoorOpen = TweenService:Create(script.Parent, DoorInfo, DoorOpenGoal)
local DoorClose = TweenService:Create(script.Parent, DoorInfo, DoorCloseGoal)

script.Parent.ProximityPrompt.Triggered:Connect(function()
	
	if isOpen == false and debounce == false then
		
		debounce = true
		isOpen = true
		
		DoorOpen:Play()
		
		wait(5)
		
		debounce = false
		
	elseif isOpen == true and debounce == false then
		
		debounce = true
		isOpen = false
		
		DoorClose:Play()
		
		wait(5)
		
		debounce = false
		
	end
	
end)
2 Likes

The problem is the goals are static values that are set when the script starts and not changed later. Change the value to the original start position of the door which is…

DoorCloseGoal.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)

or simply…

DoorCloseGoal.Position = script.Parent.Position

2 Likes

there u go here i hope it helps

3 Likes