Can someone explain this code?

Hello, I was making a door, but I found a script in the toolbox and it didn’t explain that much what was happening. Here’s the code(Just explain the math things like ToObjectSpace)

Click.MouseClick:Connect(function()
    if not opened then
        opened = not opened
        local hingeBefore = clicktoOpenPart.CFrame * CFrame.new(-2.5, 0, 0)
        
        local relative = hingeBefore:toObjectSpace(clicktoOpenPart.CFrame)
        
        local hingeAfter = hingeBefore * CFrame.Angles(0, math.rad(90), 0)
        
        local tweenProperties = TweenInfo.new(0.2) -- Time
        local result = {CFrame = hingeAfter:toWorldSpace(relative)}
        
        local tween = ts:Create(clicktoOpenPart,tweenProperties,result)
        tween:Play()
    else
        opened = not opened
        ts:Create(clicktoOpenPart, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {CFrame = oldcf}):Play();
    end
end)

That isn’t clear for me, sorry

Click this link, and find what you’re looking for: ToWorldSpace developer.roblox.com - Google Search. This might be useful too: Understanding Cframes

CFrame’s have a function named toWorldSpace(ExampleCFrame) that returns a CFrame value that is converted to world space from object space. If you don’t know what object or world space are read Object and World Space article here and Understanding CFrames article here.

Moving onto the line with CFrame.Angles(0, math.rad(90), 0), CFrame.Angles() takes 3 rotation value arguments that must be in radians which is why math.rad() is used here so we can convert an angle in degrees to radians and use it in CFrame.Angles().

Other than this, there isn’t much math related stuff in this code.