I'm trying to create a module that, when run, makes the user be able to place a block. However, when trying to place a block in a certain direction, the newly placed block clips into another block.
--My code
local mod = {}
function round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
function mod.StartPlacingBlock(bl,p)
local RS = game:GetService("ReplicatedStorage")
local EU = require(RS.ExtraUtils)
local PT = EU.GetUtility("PartTools")
local bl = RS.Items:FindFirstChild(bl):Clone()
assert(bl, "item doesn't exist")
bl.Parent = workspace
local pri = bl.PrimaryPart
assert(pri, "item has no primary part")
local mouse = p:GetMouse()
local event = Instance.new("BindableEvent")
local c = coroutine.create(function()
print("Coroutine started")
PT.AnchorModel(bl)
mouse.TargetFilter = bl
local res = true
local ext = bl:GetExtentsSize()
coroutine.resume(coroutine.create(function()
mouse.Button1Down:wait()
res = false
end))
bl.Box.Visible = true
local OH = Vector3.new(0,0,0)
local Offset = Vector3.new(0,0,0)
while res and wait() do
bl:SetPrimaryPartCFrame(CFrame.new(Vector3.new((round(mouse.Hit.Position.x/2)*2),(round(mouse.Hit.Position.y/2)*2),(round(mouse.Hit.Position.z/2)*2))))
end
print("Coroutine ended")
bl.Box.Visible = false
event:Fire()
end)
local success, err = coroutine.resume(c)
assert(success, err)
return event, c
end
return mod
There are no errors in this code, however:
Building off of this side of the pillar works fine as displayed in this image: https://prnt.sc/o4hbfl
However trying to build off the other side makes the block phase into the pillar: https://prnt.sc/o4hby2
I'm completely lost, please help.
