So i made script which detect npc or player in region but not doesn’t work.
Also if i use another script which works in the same way it works.
Script with not:
local WorkspaceService = game:GetService("Workspace")
local Region = Region3.new(Vector3.new(0,0,0),Vector3.new(15,15,15))
local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Region.Size
Part.CFrame = Region.CFrame
Part.Parent = WorkspaceService
Part.CanCollide = false
Part.Transparency = 0.9
while true do
wait()
local PartInRegion = WorkspaceService:GetPartBoundsInBox(Part.CFrame,Part.Size,OverlapParams.new(WorkspaceService.IgnorePart))
for i,v in pairs(PartInRegion) do
if v.Parent:FindFirstChild("Humanoid") == not nil then--not here
print("Player in the region:"..v.Parent.Name)
end
end
end
Script without not:
local WorkspaceService = game:GetService("Workspace")
local Region = Region3.new(Vector3.new(0,0,0),Vector3.new(15,15,15))
local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Region.Size
Part.CFrame = Region.CFrame
Part.Parent = WorkspaceService
Part.CanCollide = false
Part.Transparency = 0.9
while true do
wait()
local PartInRegion = WorkspaceService:GetPartBoundsInBox(Part.CFrame,Part.Size,OverlapParams.new(WorkspaceService.IgnorePart))
for i,v in pairs(PartInRegion) do
if v.Parent:FindFirstChild("Humanoid") == nil then
elseif v.Parent:FindFirstChild("Humanoid") then
print("Player found in the region!:"..v.Parent.Name)
end
end
end