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

Display Orientation Without the - Negative Symbol?

This script will display the Orientation By a Surface gui Text For navigation heading.

Example: The Orientation is currently at -90, When run the text will display "-90" Instead of "90" What can i do to stop the "- Negivate" Symbol from appearing?

Image Example:

https://gyazo.com/17af82021c1bcc1513b5008970dfbe15

engine = game.Workspace.Engine
texthdg = script.Parent.Main.Heading.HDGNum

while true do

	wait()

	texthdg.Text = ""..math.floor(engine.Orientation.Y)
end


2 answers

✓ Accepted answer

In order to prevent the negative number from appearing, you can use math.abs() (absolute value) on the math.floor() function:

Absolute Values change any negative number to a positive version of it, positive numbers are left alone.

Revised Local Script

local engine = workspace.Engine
local texthdg = script.Parent.Main.Heading.HDGNum

while true do
	wait()
	texthdg.Text = (""..math.abs(math.floor(engine.Orientation.Y)))
end

You can also index the Workspace using workspace instead of game.Workspace

8 comments

0

lol, my answer does say "workspace" though

0

This operates on a normal script inside a part?

0

Well, the Text is a Property under a GuiObject, so you should be using a LocalScript

0

Isn't there another way to not use local script? https://gyazo.com/249ae1d2cd257c9e8deca6ebac54c3be

0

Ok I tested it (the above code) out with that set-up, and yes it will work in a Server Script, https://gyazo.com/6c52a6427b57d207185e26bc0c56a483

0

Use whichever one you want mcandrobloxunited is just dumb

0

Hm, well in studio it appears to not function as intended.

1

Well never mind, It works! Thanks you for your help and your assist!

This answer's to be used as a reference

The answer's very simple, believe it or not. :p The answer's to use math.abs! :O

What math.abs does's it returns the number as a positive (to put very simply), or as the Dev Hub says, it returns the absolute value of x. An example of abs would be;

for i = -10, 0 do
	print(math.abs(i)) --> 10 9 8 7 ...
end

Something to note's that if the number's already positive, it wont change it to a negative. :p

for i = 0, 10 do
	print(math.abs(i)) --> 1 2 3 4 ...
end

Stuff talked about

  1. Math.abs - Returns a number as a positive.

If you have any questions, feel free to let me know. :) I hope this helped! :D

EDIT Just as I mentioned, you could try creating a variable for the orientation, then check if it's less than 0, and if so change it to a positive. An example of this's;

local YOrientation = Engine.Orientation.Y
YOrientation = YOrientation < 0 and -YOrientation or YOrientation
TextLabel.Text = tostring(YOrientation)

Please let me know if anything changes. :)

13 comments

0

i < 0 and i * -1 or i

0

i < 0 and -i or i :thonk:

0

To put it in simpler terms for you my friend: if i < 0 then i = -i end

0

No change has occur when using abs.

0

Mind showing what you've done thus far?

0

I did texthdg.Text = ""..math.abs(engine.Orientation.Y)

0

But i doubt math.abs can't be because the Workspace Engine Rotation when others say it should be run as a 'Local Script'.

0

When your using UIs it should be a LocalScript. :p However, I'm confused as to why it isn't working. :/

0

Here's a picture: https://gyazo.com/249ae1d2cd257c9e8deca6ebac54c3be The basic goal of the script is to display the Y Orientation on a surface gui.

0

Alright, so you do require a server script. What happens if you set a variable for the Y axis, then check if it's less than 0, and if so, it makes it a positive? I'll write up an example.

0

What about absolute value (the distance from 0) that way the system would print 90 either way

0

Absolute still has no result.

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