#Block placement system only works on some areas? (watch video)

1 messages · Page 1 of 1 (latest)

red saffron
#
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ghost_part = Instance.new('Part')
mouse.TargetFilter = ghost_part
local uis = game:GetService('UserInputService')

ghost_part.Size = Vector3.new(5,5,5)
ghost_part.Anchored = true
ghost_part.CanCollide = false
ghost_part.Transparency = 0.5
ghost_part.Parent = workspace
ghost_part.CanQuery = false
ghost_part.Material = Enum.Material.Brick

local grid = 5
mouse.Move:Connect(function()
    local pos = mouse.Hit.Position
    local snapped_pos = Vector3.new(
            math.round(pos.X / grid) * grid,
            math.round(pos.Y / grid) * grid,
            math.round(pos.Z / grid) * grid
        )
    
    ghost_part.CFrame = CFrame.new(snapped_pos + Vector3.new(0, ghost_part.Size.Y/2, 0))

end)

mouse.Button1Up:Connect(function()
    local clone = ghost_part:Clone()
    clone.Parent = workspace
    clone.Transparency = 0
    clone.Anchored = true
    clone.CanCollide = true
    clone.Transparency = 0
end)

uis.InputBegan:Connect(function(input, chatting)
    if chatting then return end
    if input.KeyCode == Enum.KeyCode.R then
        ghost_part.Rotation = ghost_part.Rotation + Vector3.new(0,90,0)
    end
end)```
#

This is just when placing on the side of another block.