Simple mini map

2023: I wrote this quite a while ago when I was fairly new to scripting however there’s nothing inherently wrong with the code, so I would still consider this a beginner friendly tutorial but consume it with a grain of salt as there are some unneeded steps involved, such as creating 3 part corners - you only need two and to perform some maths - and using a camera part.


Step 1) Take an overview picture of your map. This can be done by simply going into the sky and taking a screenshot then editing it on another app or using a plugin, such as Ro-Render.

Step 2) Find 3 corners of your map, make sure they share a common corner. Place a part at each of the 3 corners. Name the corner which the other 2 corners have in common to something like “Main Corner”. The others are either X1 or Y1.

Step 3) Create a part around the size of 10 x 10 depending on the ratio of your actual map and place it somewhere distant. Now create a decal, parent it to this part and import the image of your map to ROBlOX. Make sure you can see the map on the top of the part. We will now refer to this part as the minima base plate.

Step 4) Add corners to the mini map base plate in a similar manner to how you did to the actual map. E.g common corner etc. Make sure these corners are placed in the same manner as the real map corners otherwise the script will not work!

Step 5) Create a part above the minimap baseplate, we will call this part CameraPiece, I recommend like 4 studs above the minimap- this depends on how big your minimap baseplate is. Make sure the part is facing down!

Step 6) Create a screen gui, inside it a viewport frame you can add ui corners inside the viewport frame if you want the minimap to be round - and inside the viewportframe an arrow or a dot to show the player’s faced direction etc. Now inside the viewport frame create a world model and place the minimap baseplate inside it, and only the minimap baseplate. Place the corners (preferably in a folder) inside the screen gui, same with the camera piece. In the end it should look something like this.

Step 7) Inside the MainMinimapScript paste the following code, I also explained the code to the curious.

local viewportFrame = script.Parent -- stating the viewportframe
local viewportCamera = Instance.new("Camera") -- instancing a new camera to use it for the viewport frame
viewportCamera.Parent = viewportFrame -- parenting it to the viewport frame
viewportCamera.CameraType = "Scriptable" -- have to make sure its scriptable otherwise we cant change it with scripts
viewportFrame.CurrentCamera = viewportCamera -- changing the viewport's current camera to the one that we instanced


local ScreenGui = viewportFrame.Parent -- screengui variable

local MinimapCorners = ScreenGui.Corners -- minimap baseplate corners folder
local RealMapCorenrs = workspace.MapCorners -- actual corners folder
local CameraPiece = ScreenGui.CameraPiece -- part that gets moved and is aligned with our camera
	
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart") -- for location purposes


local RMC = RealMapCorenrs.X1 -- main corner in the real map. 0,0
local RX1 = RealMapCorenrs.X2 -- second corner on the x axis in the real map, e.g 1,0
local RY1 = RealMapCorenrs.Y1 -- third corner on the y axis in the real map, e.g 0,1

local MMC = MinimapCorners.X1 -- main corner on minimap baseplate. 0,0
local MX1 = MinimapCorners.X2 -- second corner on the x axis on minimap baseplate, e.g 1,0
local MY1 = MinimapCorners.Y1 -- third corner on the y axis on minimap baseplate, e.g 0,1


local RXLength = (RMC.Position - RX1.Position).magnitude -- calculating real map x axis length
local RYLength = (RMC.Position - RY1.Position).magnitude -- calculating real map y axis length

local MXLength = (MMC.Position - MX1.Position).magnitude -- calculating minimap x axis length
local MYLength = (MMC.Position - MY1.Position).magnitude -- calculating minimap y axis length

-- this was done to find the scale factor


local ScaleX = RXLength / MXLength -- x scalar for the x axis
local ScaleY = RYLength / MYLength -- y scalar for the y axis


local function movePart()
	local ActualPlayerPosition = HumanoidRootPart.Position - RMC.Position -- we minus the real map main corner position from the humanoid root part to get that position as some offset from the realmap

	CameraPiece.Position = Vector3.new(
		MMC.Position.X + (ActualPlayerPosition.X) / ScaleX, -- ok so firstly, we add the MinimapMainCorner on the baseplate to the following maths to make sure the part is placed at some position offset from the minimap main corner. Then we divide the player pos to convert the coordinates to minimap coordinates
		CameraPiece.Position.Y,
		MMC.Position.Z + (ActualPlayerPosition.Z) / ScaleY  -- same maths as previous statement but on the z axis this time instead of the x.
	)
	
	viewportCamera.CFrame = CameraPiece.CFrame -- making the viewport's camera position, what it faces towards etc, the same as that of the part's
end


local RunService = game:GetService("RunService") -- idk what this really is i wont even lie
RunService.RenderStepped:Connect(movePart) -- whenever a frame renders the function will run

For the arrow rotation paste this into the dot rotation script.

local Dot = script.Parent
local function mapPlayerPosition()
	local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
	Dot.Rotation = -HumanoidRootPart.Orientation.Y + 90
end

local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(mapPlayerPosition)

The final mini map board setup should look something like this.

41 Likes

Thank you so much for this tutorial! Now i can use this for my game! :grinning:

2 Likes

Hi I just tested your code, however I keep running into an error 'X1 is not a valid member of Folder “Workspace.MapCorners” ’ but I do have a part called X1 on the workspace in a folder called “MapCorners”, is there anything I am not doing right?

Screenshot 2024-01-04 123054

1 Like

try a waitforchild() instead of “.” as if it loads to slowly this will cause an error

2 Likes