What do you want to achieve? A building system with a grid system.
What is the issue? On the North and West of a block it doesn’t place, I assume due to the rounding equation. If its closer to one number on that side it will always round inside the block or something like that.
What solutions have you tried so far? Chat GPT. Math.floor, Math.round, Math.Celi, Etc.
All help or advice is appreciated.
Video of Issue:
Equation:
local MouseCFrame = Mouse.Hit
local MousePosition = MouseCFrame.p
local X = 4 * math.floor(MousePosition.X / 4 + 0.5)
local Y = 4 * math.floor(MousePosition.Y / 4 + 0.5)
local Z = 4 * math.floor(MousePosition.Z / 4 + 0.5)
Clone.Position = Vector3.new(X,Y,Z)
The script works perfectly fine. You just clicked on “Select” in the top bar of roblox studio (It’s obvious because you can see blue outline on the video).
Unselect it and you’ll have it.
if mouse.Target ~= nil then
if mouse.TargetSurface == Enum.NormalId.Top then
local X = mouse.Target.Position.X
local Y = mouse.Target.Position.Y + 4
local Z = mouse.Target.Position.Z
elseif mouse.TargetSurface == Enum.NormalId.Right then
--etc..
end
end
Incase anyone else had this issue, this is the code that fixed it.
local targetSurface = Mouse.TargetSurface
if targetSurface == Enum.NormalId.Bottom then
Y = Y - 4
elseif targetSurface == Enum.NormalId.Front then
Z = Z - 4
elseif targetSurface == Enum.NormalId.Left then
X = X - 4
end