Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the part of this script doing the math.tan - work, not functioning properly?

Why is the part of this script doing the math.tan - work, not functioning properly?

It returns that "a" is equal to a negative number, when it is supposed to be 0.577, why?

How can I fix this?

My coding is as follows:

function CalculateArea(s,n) --// s = side-length, n = number of sides
	local p = s*n
	local a = math.tan(180/n) --//Supposed to return 30 when n == 6, but it doesn't :-/
	print(a)
end

CalculateArea(10,6)

Any help is greatly appreciated!

1 comment

0

But the tangent of 180/6 is 0.57735026919

2 answers

✓ Accepted answer

Your issue is that math.tan is expecting an Angle in radians, not degrees.

You can convert between radians and degrees using math.rad (degrees -> radians) and math.deg (radians -> degrees), but based on your code it's just as easy to change the 180 degrees into math.pi radians:

function CalculateArea(s,n)
    local p = s*n
    local a = math.tan(math.pi/n) 
    print(a)
end

CalculateArea(10,6)

1 comment

0

Thank you!

Okay Follow My instructions 1. put that script In the workspace folder then un arrow It.2 then put it in starter guide

This discussion is preserved as it was. New answers, comments, and votes are closed.