Hi, I’m trying to get a angle of my part’s lookvector and right vector but it doesn’t seem to be right

local gizmo = require(script:WaitForChild('gizmo'))
local test = workspace.test
spawn(function()
game["Run Service"].Heartbeat:Connect(function()
gizmo.drawRay(test.Position,test.CFrame.LookVector)
gizmo.drawRay(test.Position,test.CFrame.RightVector)
local a = test.CFrame.LookVector
local b = test.CFrame.RightVector
local cos = (a.X*b.X+a.Y*b.Y+a.Z*b.Z) /((math.sqrt(a.X*a.X+a.Y*a.Y+a.Z*a.Z)) * math.sqrt(b.X*b.X+b.Y*b.Y+b.Z*b.Z))
local deg = math.acos(cos)
print(deg)
end)
end)

This is the correct answer; the max an angle of two points can ever be is pi because they are in a circle. If you divide that answer by pi and multiply it by 180, you should get the correct answer.

local part = workspace.Part
local a = part.CFrame.LookVector
local b = part.CFrame.RightVector
print(math.acos(a:Dot(b))/math.pi*180)

Using math.acos and dot is the faster way of doing your equation (I’m not too good at explaining this type of stuff, so sorry).

I commend you if you’re trying to learn to do this yourself, but if you weren’t aware Roblox does have functions to take care of this math already via LookVector:Dot(RightVector)

Also, you don’t need to use spawn here. Events run asynchronously to the rest of your code.