Before commenting "This isn't a request site" please read the entire post.
I made a block placement system but when I place block, unless it is being placed on the ground or on top of another block, 1 to 2 studs get pushed inside the side of the part you are placing on.
What happens: https://ibb.co/MgHvkGh
What supposed to happen: https://ibb.co/xsM9ym5
(Not a ip logger)
Here is my code for the hover placing:
script.Parent.Equipped:Connect(function() -- Activate when tool eqquiped
if mouse ~= nil then -- Check if mouse exists
eqquiped = true
local clone = game.ReplicatedStorage.Dirt:Clone() -- Creates clone
clone.Name = "placing"
mouse.TargetFilter = clone -- Mouse not effected by clone
for i,v in pairs(clone:GetChildren()) do -- Set all parts to transparency 0.5
if v.Name ~= "hit" then
v.Transparency = 0.5
end
end
clone.Parent = workspace -- Move the part
mouse.Move:Connect(function()
if eqquiped then
if clone then
clone:SetPrimaryPartCFrame(CFrame.new(snap(mouse.Hit.p,3))) -- Set the part position
end
end
end)
end
end)
Code for actual placing:
script.Parent.Activated:Connect(function()
local clone = game.ReplicatedStorage.Dirt:Clone() -- Creates clone
clone.Parent = workspace -- Move the part
clone:SetPrimaryPartCFrame(CFrame.new(snap(mouse.Hit.p,3))) -- Set the part position
end)
snap() is a function that takes in a vector3 and a float, it returns a vector3 snapped to a grid:
function snap(pos,grid)
return Vector3.new(
math.floor((pos.X / grid) * grid + 0.5),
math.floor((pos.Y / grid) * grid + 2),
math.floor((pos.Z / grid) * grid + 0.5)
)
end
My idea is that the block ejects out of the part you are hovering over, but still keep the grid system.

21 comments
It dosnt work. It ejects the block out of the side but it is a bit off the ground
i updated the answer to ((((hopefully)))) work now
in the snap function what would normal be? when i call the function?
you don't have to include it if you're just trying to snap a normal position to the grid, but when you use it for block placement, it's the normal of the surface the player is hovering over
i included some code that does it for you
the snap function need to be in a cframe, so it looks like this : CFrame.new(snap(arg,arg2,arg3)
oops you're right, my bad
this is almost working but the block is being placed on the side of the block that is being placed (the transparent one)
try adding the transparent clone to the filter list when you actually place the block
where is the filter?
wait dont tell me i need to figure this out on my own
the filter is the line that sets params.FilterDescendantsInstances
the filter is the line that sets params.FilterDescendantsInstances
the clone is already in the blacklist
no, i mean the transparent clone, the clone variable when you place the block is different than the transparent clone variable
you need to create a transparentClone variable at the top of the script and set the transparent clone to that
what would i set t he transparent clone value to be?
you don't need to set it to anything until the player equips the tool
oh im dumb i need to set this in the placing part of the script! my bad
thanks you you are the first person to actually attempt to anwser my question!'
np