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
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”.
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!