Intro
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.
Problem
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.
Code
local function onClick1()
local newPart = part:Clone()
newPart.Parent = workspace.Map
newPart.Position = part.Position
end
mouse.Button1Down:Connect(onClick1)
local function onUpdate()
if mouse.Target == nil then
return
end
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
end
local blockPos = block.Position
local newPos = Vector3.new(blockPos.X + xDif, blockPos.Y + yDif, blockPos.Z + zDif)
part.Position = newPos
end
end
RS:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate)
How can I fix this?