Not doesn't work[SOLVED]

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

I’d assume this would be why, if you put not infront of the code you’re trying to avoid not returning nil you should do this instead:

if not v.Parent:FindFirstChild("Humanoid") == nil then -- rest of the code

Or, you could do:

if v.Parent:FindFirstChild("Humanoid") ~= --[[~= is just like not.]] nil then -- rest of the code
1 Like

you can’t put == and not and nil like that what you could try to do is just

if v.Parent:FindFirstChild("Humanoid") then
			print("Player in the region:"..v.Parent.Name)
		end
2 Likes

Thanks for fast and right reply with solution.

1 Like

Thanks, it works too, but i can’t put 2 solutions, sorry.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.