I am trying to make a command that clears parts that are outside of the plot, and sooner or later once this command seems to be working fine then I’ll make it completely automatic to mitigate glitches.
Now, the issue I’m having here is either this script detects no parts in the Region3 (currently) or it detects all of the parts, depending on how I’ve adjusted the script. It never runs the way I want it to; I’m not sure why this is, as I’ve dealt with Region3s before.
if cmdArgs[1] == "cop" or cmdArgs[1] == "clearoutsideparts" then -- Don't worry about this.
if plr:FindFirstChild("SavingPlot") then -- Don't worry about this.
display("command failed; player is currently saving / loading")
return
end
local pba = workspace:FindFirstChild("Private Building Areas")
local plot = pba:FindFirstChild(plr.Name .. "BuildArea")
local hmr = plr.Character:FindFirstChild("HumanoidRootPart")
if plot == nil then -- Don't worry about this except for "else".
display("plot area not created")
else
local min = (CFrame.new(plot.Position) * CFrame.new(-plot.Size.x/2, -plot.Size.y/2, -plot.Size.z/2)).Position
local max = (CFrame.new(plot.Position) * CFrame.new(plot.Size.x/2, plot.Size.y/2, plot.Size.z/2)).Position
local PlotRegion = Region3.new(min,max)
local PartsInRegion3 = workspace:FindPartsInRegion3(PlotRegion, nil, 4096)
for _,v in pairs(PartsInRegion3) do
print(tostring(v))
end
for _,v in pairs(plot:GetDescendants()) do
if v:IsA("BasePart") then
if table.find(PartsInRegion3, v) then
print("Found part: "..v.Name)
elseif not table.find(PartsInRegion3, v) then
print("Found outside part: "..v.Name)
v:Destroy()
end
end
end
end
end
00:38:43.662 LainnascusBuildArea - Server - LCSMain:1684
00:38:43.662 Baseplate - Server - LCSMain:1684
00:38:43.662 ▶ Found outside part: Part (x2) - Server - LCSMain:1692
Any form of help would be strongly appreciated.