How to make a Basic Compass System

Hello Developers,

I’m Woodx and I’d make the tutorials in a very short and a simple way
In this tutorial, you will get to know how to do a compass in less than 25 lines of scripting

This uses basic maths and achieves this, I read many tutorials to make a compass system, but I couldn’t find any easy tutorial, so I decided to make my own tutorial if there isn’t one which I needed already

Step 1 Knowing the simple framework of this

In Roblox, orientation exists of 3 vectors
(x,y,z)
Now here, the left/right is the Y-axis.

Now imagine I am looking at 0 degrees, and the max in Roblox is 0-180, and 180-0, it can also be -92,95,125,-179 but it won’t exceed 180 or -180

So if you got -180 or 180 it means 2x perpendicular to the origin, which is South
And same way for other directions

Step 2 Making the UI

It’s just a textlabel in my tutorial


You can make your UI, however, to keep it very simple, I made it like this
image

Making it work

Now add a local script in your text label text button or textbox, now this is the script

local rs = game:GetService("RunService")
local part = Instance.new("Part")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local tableofp = {
	["2"] = "South",
	["1"] = "West",
	["0"] = "North",
	["-0"] = "North",
	["-1"] = "East",
	["-2"] = "South"
}
-- Example : (-2)* 80 = -180 = 180 degrees of north = south
local function showdirection()
	part.CFrame = game.Workspace.CurrentCamera.CFrame
	local direction = tableofp[tostring(math.round(part.Orientation.Y/90))]
	script.Parent.Text = direction
end

workspace.CurrentCamera.Changed:Connect(showdirection) -- the function runs when the mouse is moved to change the direction, however, if the game bugs or the function wants to run itself without any firing, it will also get fired

That’s it, if you wanna hire me or support me, check the Support Me page.

Support me

Paypal

If you also wanna make the North East, North West, and South West/East it is simple, but I’m not telling it in this tutorial as the Title says it’s a basic system, not an advanced one.

14 Likes

Maybe use workspace.CurrentCamera.Changed instead of mouse.move() ?

2 Likes

Mouse can be moved several times, even when browsing through the user interface, this will cause the function to run many times unnecessarily.

2 Likes

You use mouse.Move in your script…

1 Like

lmaoo bruhh aint no way. :sob:

1 Like

:sob: aint no way he forgot what he put in his own script

2 Likes

Actually yes, I forgot to change it, it was when the workspace.CurrentCamera.Changed wasn’t firing properly before, so I kept mouse.Move, I updated the tutorial, thank you for telling it. Sorry, I didn’t understand you properly before :slight_smile:

2 Likes