im trying to make a door that slides into the floor and i am using this code
local TweenService = game:GetService("TweenService") local Panel = workspace.UnlockedDoor.door local PanelRoot = Panel.PrimaryPart local PanelSlideInfo = TweenInfo.new() local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, { CFrame = PanelRoot.CFrame * CFrame.new(PanelRoot.Size.Y + 0, 0, 0) }) wait(3) PanelSlideTween:Play()
when i run the script the door keeps going to the right, i want the door to move down, but no matter what XYZ i plug into the vector3 it just wont change. whats wrong?
Hello!
CFrame
s are relative to the rotation of the object. For example, if I were to rotate a object 90 degrees couterclockwise in the Z axis, and then tried moving it 5 studs to the right in the X axis, it would go up instead of right, because CFrames are relative, or something. I am bad at explaining stuff.
Anyways, you can only add CFrame
s with the symbol *
, which, despite common sense, adds CFrame
s instead of multiplying them. To get around that, you need to have a negative number instead of a positive number, like this:
CFrame = PanelRoot.CFrame * CFrame.new(-PanelRoot.Size.Y, 0, 0) --negative
If you're confused, you can see a detailed article about CFrames here, or, alternatively, you can ask me questions that aren't located in the article.
I hope this helps! Please excuse my bad explanation.