Why is my region3 still detecting the player outside the desired box?
I have this script here
local regionPart = game.Workspace:WaitForChild("SuffocationArea")
local pos1 = regionPart.Position - (regionPart.Size /2)
local pos2 = regionPart.Position + (regionPart.Size /2)
local region = Region3.new(
Vector3.new(
math.min(pos1.X, pos2.X),
math.min(pos1.Y, pos2.Y),
math.min(pos1.Z, pos2.Z)
),
Vector3.new(
math.max(pos1.X, pos2.X),
math.max(pos1.Y, pos2.Y),
math.max(pos1.Z, pos2.Z)
)
)
local cansuffo = script.Parent.can_suffocate
while wait(1) do
local partsInRegion = workspace:FindPartsInRegion3(region,nil,1000)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
cansuffo.Value = false
break
else
cansuffo.Value = true
break
end
end
end
Perfect region3, But even if I leave the game.Workspace.SuffocationArea It still detects my player character!
local regionPart = game.Workspace:WaitForChild("SuffocationArea")
local pos1 = regionPart.Position - (regionPart.Size /2)
local pos2 = regionPart.Position + (regionPart.Size /2)
local region = Region3.new(
Vector3.new(
math.min(pos1.X, pos2.X),
math.min(pos1.Y, pos2.Y),
math.min(pos1.Z, pos2.Z)
),
Vector3.new(
math.max(pos1.X, pos2.X),
math.max(pos1.Y, pos2.Y),
math.max(pos1.Z, pos2.Z)
)
)
local cansuffo = script.Parent.can_suffocate
while wait(1) do
local partsInRegion = workspace:GetPartBoundsInBox(region,nil,1000)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
cansuffo.Value = false
break
else
cansuffo.Value = true
break
end
end
end
local regionPart = game.Workspace:WaitForChild("SuffocationArea")
local cansuffo = script.Parent.can_suffocate
while wait(1) do
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Include
Params.FilterDescendantsInstances = {workspace}
local PartBoundsInBox = workspace:GetPartBoundsInBox(regionPart.CFrame, regionPart.Size, Params)
for i, part in pairs(PartBoundsInBox) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
cansuffo.Value = false
break
else
cansuffo.Value = true
break
end
end
end
It still doesnt work for some reason! No errors in output or anything, Just still works when im not in the box
Edit: I got it working! Thanks for your help man! If you’re curious, Here is the working script
local regionPart = game.Workspace:WaitForChild("SuffocationArea")
local cansuffo = script.Parent.can_suffocate
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Include -- Exclude / Include
Params.FilterDescendantsInstances = {Instance}
while wait(1) do
local region = regionPart
local boxPosition = region.CFrame
local boxSize = region.Size
local parts = workspace:GetPartBoundsInBox(boxPosition, boxSize, nil)
for _, part in pairs(parts) do
if part.Parent.Name == game.Players.LocalPlayer.Name then
cansuffo.Value = true
break
else
cansuffo.Value = false
end
end
end