You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to make the chest open even if i change the scale of its model, rotate it or change position
What is the issue? it works when i move it but when i change the orientation of the chest it breaks.
What solutions have you tried so far? Tried looking in help channels and using chatgpt i also found a fix i think by using a hinge but it’s not the best way to animate it. Chat Gpt is dumb by the way
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- // Services
local TS = game:GetService("TweenService")
--// Essentials
local Chest = script.Parent
local Head = Chest:WaitForChild("Head")
local Bottom = Chest:WaitForChild("Bottom")
local ancientCframe = Head.CFrame
local scale = Chest:GetScale()
local offsetX = -9.8
local offsetY = 10
local offsetZ = -16.975
local scaledOffsetX = offsetX * scale
local scaledOffsetY = offsetY * scale
local scaledOffsetZ = offsetZ * scale
local goalCFrame = CFrame.new(
ancientCframe.X + scaledOffsetX,
ancientCframe.Y + scaledOffsetY,
ancientCframe.Z + scaledOffsetZ
) * CFrame.Angles((Head.Orientation.X), math.rad(Head.Orientation.Y), math.rad(90))
local Open_Anim = TS:Create(Head, TweenInfo.new(1), {CFrame = goalCFrame})
Open_Anim:Play()
CFrame.Angles dont use typical degrees
It use Pitch,Yaw and Roll (learn eulers math to understand this terms) its a fromEulerAnglesXYZ constructor behind the scenes actually.
If you want short answer just use CFrame.fromEulerAnglesYXZ instead
Instead of doing math.rad(90) that has some overhead i recomend you to cache constant somewhere “math.pi*0.5”
put variable referancing this value where you declear services etc
So it can be accesed in code below.
In other programming languages like c for example there is a keyword “const”
const int newconstant = 42;
Its refering to immutable variable
While in Luau there is no official “constants” this term is still commonly used and is often a good programming habbit.
Compiled to machine code Luau does create constants probably tho if variable doesnt get mutated i think
I could be wrong tho.
i wasn’t talking about constants tho i asked how to fix my issue because i don’t really understand why when you change orientation the axis change when you play the game
If you don’t wanna do this using math, there is a more, albeit probably lazier way you can achieve this effect:
Make a clone of the top part and position and rotate it at where you want the opened top part position to be, then take either a part and copy the top part’s position and orientation to it, make it a child of the chest model.
Then you could just tween the head to that respective target part’s cframe, you just have to save the chest lid’s original CFrame to a variable if you ever want to tween it back.
EDIT: I think only parts would work, don’t use attachments since I think scaling doesn’t change their relative positions