Minimap Scripting Help

Hi, I’m trying to script a minimap in-game. The image is supposed to move based on the player’s position but when I play the game, the map’s position is moved off the frame. The map moves according to my position, it’s just too far from the frame for some reason.

Expectation:
image

Reality:
image

Code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()

local minimap = script.Parent.Parent
local mapImage = minimap:WaitForChild("Container"):WaitForChild("Map")

local hrp = character:WaitForChild("HumanoidRootPart")

game:GetService("RunService"):BindToRenderStep("OffScreenIndicator", Enum.RenderPriority.Camera.Value -1, function() 
	local positionx = (minimap.AbsoluteSize.X - hrp.Position.X) - (mapImage.AbsoluteSize.X - minimap.AbsoluteSize.X/2)
	local positiony = (minimap.AbsoluteSize.Y - hrp.Position.Z) - (mapImage.AbsoluteSize.Y - minimap.AbsoluteSize.Y/2)
	
	mapImage.Position = UDim2.new(0,positionx,0,positiony)
end)

Explorer:
image

Thanks :stuck_out_tongue:

4 Likes

Have you checked what the values positionx and positiony result in?

I would try and systematically print the values to see if anything is freaking out.

1 Like

I did, its nothing abnormal. Its like 11.blabla, 0,30.blabla,0 and the position updates as the player moves. The image is just too far away for some reason.

Try changing this so you instead fetch the minimap with starterplayer folder instead. I’ve had some problems with images before and this solved it sometimes.

If those numbers are correct then the problematic line is more than likely:

mapImage.Position = UDim2.new(positionx/Viewport_Size.X,0,positiony/Viewport_Size.Y, 0)

Have you checked what positionx/Viewport_Size.X results in?

Edit:

I see the issue I think! Try and replace the line I said above with:
mapImage.Position = UDim2.new(0,positionx,0,positiony)

Changing the position to Offset has the same issue.

No thats not the issue, the script runs its just too far away

I included a pic of the explorer and edited the code as suggested by @grilme99

Possibly the issue was due to using Offset or using AbsoluteSize. Try using Scale instead.
There’s an example of Minimap: Baseplate.rbxl (21.0 KB)

1 Like

image

i used the script in the template but it doesn’t seem to be calibrated, how do I calibrate it?

image
seems to work when i walk far away from my map

I added AnchorPoint now: Baseplate.rbxl (21.5 KB)
(Sidenote: I also added “Zoom out” feature, look pretty cool.)

What so you mean? I can set the centre of the map? How do i calibrate it

By changing AnchorPoint, you’ll be able to move Image map while standing at same position as before.

Before (Vector3.new(0,0,0)):


After (Vector3.new(256,0,256)):

(I forgot to flip the Value X and Y, you only need to negative it… or here: Baseplate.rbxl (21.5 KB) )

1 Like

Moving forward seems to move backwards on the map, any way to reverse the up-down axis? I tried changing to the negative signs and etc. but doesn’t work