Im trying to find an angle between 2 parts, what's wrong with my script?

Im putting my recently learned knowledge of Trigonometry to the test, What did I did do wrong in this script?

I took both X and Y distances, and used atan (Opposite/Adjavent) to try and find the angle, Whats wrong here?

local t1 = game.Workspace.t1
local t2 = game.Workspace.t2
local run = game:GetService("RunService")

run.RenderStepped:Connect(function()
local directionY = (t2.Position.Y - t1.Position.Y) -- Distance Y
local directionX = (t2.Position.X - t2.Position.X) -- Distance X

      wait(.5)                      --Opposite-- --Adjacent--
	local angle = math.atan(math.rad(directionY/directionX))
	print(angle)
	
end)


Direction y over direction x is a ratio of the length of the triangle.

There shouldn’t be a need to convert it to radians as it’s not an angle yet in degrees. Try removing math.rad

1 Like