Well, I’m trying to make a grid placement system with 4x4x4 blocks, and I can only place on positive axis. When I try and place on negative axis, it places in the block I’m clicking on.
Code:
player = game.Players.LocalPlayer
mouse = player:GetMouse()
local selectionbox = Instance.new("SelectionBox")
selectionbox.Color3 = Color3.fromRGB(150, 0, 32)
selectionbox.Visible = true
selectionbox.LineThickness = .01
selectionbox.Parent = player.PlayerGui
local selectionbox2 = Instance.new("SelectionBox")
selectionbox2.Color3 = Color3.fromRGB(18,230,3)
selectionbox2.Visible = true
selectionbox2.LineThickness = .01
selectionbox2.Parent = player.PlayerGui
mouse.Button1Down:Connect(function()
if player.BlockSettings.Value == 1 then
local pos = mouse.Hit
local posX = math.floor(mouse.Hit.Position.X / 4 + 0.5) * 4
local posY = math.floor(mouse.Hit.Position.Y / 4 + 0.5) * 4
local posZ = math.floor(mouse.Hit.Position.Z / 4 + 0.5) * 4
game.ReplicatedStorage.PlaceBlock:FireServer(posX,posY,posZ)
elseif player.BlockSettings.Value == 2 then
if mouse.Target.Name == "Dirt" then
local target = mouse.Target
game.ReplicatedStorage.BreakBlock:FireServer(target)
end
else
end
end)
mouse.Move:Connect(function(target)
if player.BlockSettings.Value == 1 then
if mouse.Target.Name == "Dirt" then
selectionbox2.Adornee = mouse.Target
else
selectionbox2.Adornee = nil
end
elseif player.BlockSettings.Value == 2 then
if mouse.Target.Name == "Dirt" then
selectionbox.Adornee = mouse.Target
else
selectionbox.Adornee = nil
end
end
end)