Grid placement system not moving correctly

Basically, I made a script from a grid placement system tutorial, since I don’t know how to make this correctly. It works fine when the step is 1, however if I change it, the part doesn’t spawn at the mouse’s location, but rather somewhere 1000 studs away. What could be the issue?

Script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local Block = script:WaitForChild("Block")
Block.Anchored = true
Block.Orientation = Vector3.new(0,0,0)

local BlockGhost = Block:Clone()
BlockGhost.Parent = workspace
BlockGhost.Transparency = 0.5
BlockGhost.CanCollide = false

Mouse.TargetFilter = BlockGhost

local step = 4

Mouse.Move:Connect(function()
	local MousePos = Mouse.Hit.Position
	local BlockPos = Vector3.new(0, Block.Size.Y / 2, 0)
	BlockPos += MousePos
	
	local XPos = math.round(BlockPos.X / step)
	local YPos = math.round(BlockPos.Y)
	local ZPos = math.round(BlockPos.Z / step)
	BlockPos = Vector3.new(XPos, YPos, ZPos)
	
	local tween = tweenservice:Create(BlockGhost, info, {Position = BlockPos}):Play()
end)

Mouse.Button1Down:Connect(function()
	local NewBlock = Block:Clone()
	NewBlock.Parent = workspace.Blocks
	NewBlock.Position = BlockGhost.Position
end)

Instead of adding the blockPos you can add a mouse filter.
Also adding the character to the filter is handy.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.TargetFilter = {player.Character, block}

And for the gridded position of the block do this:

local XPos = math.round(BlockPos.X / step) * step
local YPos = math.round(BlockPos.Y / step) * step
local ZPos = math.round(BlockPos.Z / step) * step

You might have to adjust some things to your liking.