i am trying to make my grid building system not let you place blocks inside of each other
on 2 of the axis it lets me place blocks inside of each other
Video of what is going on
i have tried 2 tutorials
here is the local script for the placement grid that i made
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local block = game.ReplicatedStorage:WaitForChild("Blocks"):WaitForChild(script.Parent.Name)
local ghostBlock
local step = 3
local positions = {}
tool.Equipped:Connect(function()
ghostBlock = block:Clone()
ghostBlock.Parent = workspace
ghostBlock.Anchored = true
ghostBlock.CanCollide = false
ghostBlock.Transparency = 0.5
mouse.TargetFilter = ghostBlock
repeat
wait()
local mousePos = mouse.hit.Position
local xPos = math.round(mousePos.X / step) * step
local yPos = math.round(mousePos.Y/ step) * step + 1.5
local zPos = math.round(mousePos.Z / step) * step
if not table.find(positions,Vector3.new(xPos,yPos,zPos)) then
ghostBlock.Position = Vector3.new(xPos,yPos,zPos)
else
print(xPos,yPos,zPos)
ghostBlock.Position = Vector3.new(xPos,yPos,math.abs(zPos))
end
until tool.Parent == player.Backpack
ghostBlock:Destroy()
end)
tool.Activated:Connect(function()
game.ReplicatedStorage.Place:FireServer(ghostBlock.Position,tool.Name)
table.insert(positions,ghostBlock.Position)
end)