--LocalScript in StarterPlayerScripts
local rs = game:GetService("RunService")
local center = workspace:WaitForChild("Center")
local wall = workspace:WaitForChild("Wall")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 8
rs.Stepped:Connect(function()
local mousePos = mouse.Hit.Position
local localPos = center.CFrame:PointToObjectSpace(mousePos)
local gx = math.round(localPos.X / grid) * grid
local gz = math.round(localPos.Z / grid) * grid
local left = Vector3.new(gx - grid/2, 0, gz)
local right = Vector3.new(gx + grid/2, 0, gz)
local distLeft = (localPos - left).Magnitude
local distRight = (localPos - right).Magnitude
local chosen = distLeft < distRight and left or right
local worldPos = center.CFrame:PointToWorldSpace(chosen)
wall:PivotTo(CFrame.new(worldPos) * CFrame.Angles(0, math.rad(90), 0))
end)
You can use the </> option when posting scripts, to put them in these code boxes.
Thank you for not using a picture.
A rem can do that if it has a … in it. Or it runs into an odd … in the script.
Keep in mind your object walls need to be twice as long as your grid size to line up at the corners if one is rotated (making a corner). If your walls are 8 studs long, your grid should be 4.