You can write your topic however you want, but you need to answer these questions:

What do you want to achieve? I want angles go full 360° instead of half circle

What is the issue? It prints -179° to -1° instead of full circle

What solutions have you tried so far? I haven’t found any solutions

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!

local part1 = workspace.Part1
local part2 = workspace.Part2
local angle = 0
local function circle(angle,magnitude)
local x = -math.cos(math.rad(angle)) * 7
local z = math.sin(math.rad(angle)) * 7
return x,z
end
game:GetService("RunService").Heartbeat:Connect(function(dt)
angle += 1
local relativity = part2.CFrame:ToObjectSpace(part1.CFrame)
local angledebug = math.deg(math.atan2(relativity.X,relativity.Z))
local x,z = circle(angle)
part2.Position = part1.Position + Vector3.new(x,0,z)
print("Angle between two parts is: "..math.floor(angledebug).."°")
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Your script works just fine and everything is mathematically correct.

The reason you’re getting this error is related to the floating point imprecision. Because you’re flooring the result, the step is occasionally going to show as 0, as the difference will be almost 1 but slightly less, such as 0.998.

See this small modification

Please ignore the initial difference of 90 deg. It’s there because debug angle values are still 0 in the first cycle.

local part1 = workspace.Part1
local part2 = workspace.Part2
local angle = 0
local debugAngle = 0
local prevDebugAngle = 0
local function circle(angle, magnitude)
local x = -math.cos(math.rad(angle)) * 7
local z = math.sin(math.rad(angle)) * 7
return x, z
end
part2.Position = part1.Position + Vector3.new(-7,0,0)
game:GetService("RunService").Heartbeat:Connect(function(dt)
angle += 1
angle = (angle == 361) and 0 or angle
local relativity = part2.CFrame:ToObjectSpace(part1.CFrame)
prevDebugAngle = debugAngle
debugAngle = math.deg(math.atan2(relativity.X,relativity.Z))
local x,z = circle(angle)
part2.Position = part1.Position + Vector3.new(x,0,z)
if debugAngle - prevDebugAngle < .95 or debugAngle - prevDebugAngle > 1.05 then
print("Difference: "..debugAngle - prevDebugAngle)
end
end)

The difference was meant for alternative illustration that the script works as expected, and to show that each angle step is proper, which was not an issue and an overlook on my part.

Can you please elaborate on your use case? I can’t reproduce the issue. Here’s your original script in action.

This is it. Sorry if I caused any confusion, idk what I was thinking.

It’s not uncommon for angles to be represented in range from -180 to 180 instead of from 0 to 360. It’s a supported design decision (though normal 360-degree representation works in Roblox too). A range from -180 to 180 means 0 would be a straight angle in relation with the 360-degree system, and -180 as well as 180 represent the same angle. But in game development it’s normally interpreted as no rotation. Comparing positive against negative angles is often more practical. FOV 140 would mean -70 to the left and 70 to the right. Or imagine a gyro/attitude horizon instrument in airplanes.