Tilemap second layer offset when used programmatically

Godot Version

4.2.1

Question

I’m attempting to dynamically add a layer to a tile map on mouse over. The effect is working but I’m running into an issue. I’ve offset the tile map from the edge of the screen, it’s like a gameboard in the middle of the screen with UI on either side.

The issue the tile highlights roughly three tiles to the right of where the cursor is (see screenshot):

This is my script:

extends TileMap

var gridSize = 8
var dictionary = {}

func _ready():
	for x in gridSize:
		for y in gridSize:
			dictionary[str(Vector2(x, y))] = {
				"Type": "Black",
				"Occupied": false
			}
			set_cell(0, Vector2(x, y), 0, Vector2i(0, 0), 0)

func _process(delta):
	var currentTile = local_to_map(get_global_mouse_position())
	
	if dictionary.has(str(currentTile)):
		set_cell(1, currentTile, 1, Vector2i(0, 0), 0)

If I move the tile map starting point in the 2d editor to 0,0 I don’t have this problem.

I’m still very new to this engine so I don’t know if I’m missing something? Any help would be greatly appreciated.

Solved, I needed to use get_local_mouse_position rather than get_global_mouse_position