Mouse Target Surface Problem

Hello! I am having an issue with the mouse.TargetSurface. I am creating a block placement system. The system works by getting the mouse.Target and the mouse.TargetSurface.

When a block is placed I want the mouse.Target and mouse.TargetSurface to update to the new Block. Yet what actually happens is that it stays at the old. This allows blocks to be placed in the same spot.


local function onClick1()
	local newPart = part:Clone()
	newPart.Parent = workspace.Map
	newPart.Position = part.Position


local function onUpdate()
	if mouse.Target == nil then
	if mouse.Target:IsDescendantOf(workspace.Map) then
		local block = mouse.Target
		local surface = mouse.TargetSurface
		local xDif = 0
		local yDif = 0
		local zDif = 0
		if surface == Enum.NormalId.Top then
			yDif = 3
		elseif surface == Enum.NormalId.Bottom then
			yDif = -3
		elseif surface == Enum.NormalId.Front then
			zDif = -3
		elseif surface == Enum.NormalId.Back then
			zDif = 3
		elseif surface == Enum.NormalId.Right then
			xDif = 3
		elseif surface == Enum.NormalId.Left then
			xDif = -3
		local blockPos = block.Position
		local newPos = + xDif, blockPos.Y + yDif, blockPos.Z + zDif)
		part.Position = newPos

RS:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate)

How can I fix this?

1 Like

It seems that even though you redefine mouse.TargetSurface each renderstep, it does not update because the mouse is not moving.

Perhaps you could make a variable that waits for you to move the mouse just the slightest bit until you can build again, that way they can’t put anything exactly the same spot and your mouse will update to the new TargetSurface.

1 Like