Why isn't this moving along the Y axis?

New to this. Trying to get the hang of tweening and using Vector3 values, CFrames, all that good stuff.
Right now I’m trying to make it that when this function runs my door lifts for ten secondsand then goes back down into it’s starting position. What’s happening instead is that it’s moving to 0,10,0. But when the 10 seconds are up, it lowers itself on the y axis just fine. Why isn’t it lifting like I’d like, but closing correctly?

function openDoor()

	local startPos = Vector3.new(door.CFrame)
	local goal = startPos + Vector3.new(0,10,0)
	
	local TweenService = game:GetService("TweenService")
	
	local TwInfo = TweenInfo.new(4)
	local opTween = TweenService:Create(door,TwInfo,{Position = goal})
	local clTween = TweenService:Create(door,TwInfo,{Position = startPos})
	local sfx = door.open
	
	sfx:Play()
	opTween:Play()
	task.wait(10)
	sfx:Play()
	clTween:Play()

end

is the door anchored? if not, try that.

You can’t create a Vector3 from base CFrame without modifications, I suggest using the CFrame of the door to do that instead

local startPos = door.CFrame
local goal = startPos * CFrame.new(0,10,0)
local TweenService = game:GetService("TweenService")
	
	local TwInfo = TweenInfo.new(4)
	local opTween = TweenService:Create(door,TwInfo,{CFrame = goal})
	local clTween = TweenService:Create(door,TwInfo,{CFrame = startPos})
...the rest of the code

When I do this, it throws an error instead:
" TweenService:Create property named ‘Position’ cannot be tweened due to type mismatch (property is a ‘Vector3’, but given type is ‘CoordinateFrame’)"

Tried to change “{Position = goal}” to just “goal” etc, but that tells me it’s “unable to cast to dictionary”.

I’m very confused!

Bumping because I still can’t figure out where I’m going wrong here. I may be stupid but I truck on regardless

You’re still telling TweenService to tween the Position of your door rather than the CFrame.

If you look at the solution provided above, you can see the author changed the tween property tables (3rd argument in TweenService:Create) from

{Position = goal}
{Position = startPos}

to

{CFrame = goal}
{CFrame = startPos}

The property type and value type have to match otherwise you will get an error like you did.

Hope this helped :slight_smile:

1 Like

OH, YOU’RE RIGHT, I totally missed that part. I thought Position and CFrame were the same thing, but I guess not. Thank you so much, I’ll keep that bit in mind from now on!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.