I am working on a building system for my game, and I check if you are building on your plot by creating a temporary part where you are attempting to build, and if it is in the Region3 of that plot, then it places the object. My problem is that after some blocks have been placed, some regions of the Region3 go unchecked, returning that the temporary part is not in the region.
Code:
game.ReplicatedStorage.Buildables.reqBuild.OnServerEvent:Connect(function(player, pos, item, color, material, color2, material2, hazard)
local function build()
local piece = game.ReplicatedStorage.Buildables:WaitForChild(item)
local part = piece:Clone()
part:SetPrimaryPartCFrame(pos)
for _, object in pairs(part:GetChildren()) do
-- Decorates object
end
part.Parent = game.Workspace.Placed_Blocks
game.ReplicatedStorage.Buildables.reqBuild:FireClient(player)
end
local tempPart = Instance.new("Part")
tempPart.Size = Vector3.new(1, 1, 1)
tempPart.CanCollide = false
tempPart.Transparency = 1
tempPart.Position = pos.p -- Requested position from CFrame to Vector3
tempPart.Parent = workspace.Ignore_Blocks
tempPart.Name = "tempPart_" .. player.Name
tempPart.Anchored = true
workspace.Ignore_Blocks:WaitForChild("tempPart_" .. player.Name)
for _, object in pairs(workspace.Stuff.Build_Plates:GetChildren()) do
if object.Owner.Value == player.Name then
--The buildplate has 2 Vector3 values for the corners of the area.
--Corner1 contains the lowest values, Corner2 contains the higher
local region = Region3.new(object.Corner1.Value, object.Corner2.Value)
for _, object in pairs(workspace:FindPartsInRegion3(region)) do
print(object.Name)
if object == tempPart then
tempPart:Destroy()
tempPart = nil
build()
end
end
region = nil
if tempPart then
tempPart:Destroy()
tempPart = nil
game.ReplicatedStorage.Buildables.reqBuild:FireClient(player)
end
end
end
end)

5 comments
Have you tried raising corner2?
Yes, it's broken at every Y-value for corner2
Have you tried lowering corner1?
Also why do you have that section after line 35?
region = nil, tempPart:Destory(), and tempPart = nil is unnecessary, sorry, but that just tells the client that it acknowledged the object.