The red block should fill between the walls using raycast. Something with my math is wrong im pretty certain…
local part = script.Parent
local origin = part.Position
local hitPositions = {}
local directions = {
Vector3.new(-10,0,0); -- left
Vector3.new(10,0,0); -- right
Vector3.new(0,0,10); -- top
Vector3.new(0,0,-10); -- bottom
}
for _,direction in ipairs(directions) do
local result = workspace:Raycast(origin, direction*2)
local hitPosition = (result and result.Position) or origin + direction*2
table.insert(hitPositions,hitPosition)
local t = Instance.new("Part",workspace)
t.Position = hitPosition
t.Anchored = true
t.CanCollide = false
t.CanQuery = false
t.Size = Vector3.new(2,2,2)
game.Debris:AddItem(t,.03)
end
local sizeX = hitPositions[2].X - hitPositions[1].X
local sizeZ = hitPositions[3].Z - hitPositions[4].Z
local pos = (hitPositions[1] + hitPositions[2] + hitPositions[3] + hitPositions[4])/4
part.Size = Vector3.new(sizeX,0,sizeZ)
part.Position = pos