Why is this not working as expected?

local Parts = workspace:FindPartsInRegion3WithIgnoreList(GetRegion(workspace.Map.CopRespawn.CopRemover),{workspace.Vehicles,workspace.Map.Buildings,workspace.Map["Highways & Roads"],workspace.Map.Buildings,workspace.Map.Dealership},math.huge)
	for i,v in ipairs(Parts) do

		local ot = game.Players:GetPlayerFromCharacter(v.Parent)

	
			if (ot == player) then
				inarea = true
				print('i')
				player.PlayerGui.Game.FrameWork.safezone.Visible = true
			elseif (not ot == player) then
				 	inarea = false
				player.PlayerGui.Game.FrameWork.safezone.Visible = false
				print('o')
		end
	
		end

^ That’s my code
For some reason, when checking for elseif (not ot == player) then it’s not working, i’m trying to check if the player is outside a region (safe zone)

local ot = game.Players:GetPlayerFromCharacter(v.Parent)

ot is either a player or nil.
With that in mind, you can do the following:

			if ot then
                --ot is a player
				inarea = true
				print('i')
				player.PlayerGui.Game.FrameWork.safezone.Visible = true
			else 
            --ot is not a  player, so we cant index player.PlayerGui since ot is nil
		    end
	

This would work, but, if other player is in it would detect him.

The problem is that line of code. (not ot == player), really you should use ot ~= player

Observe:

not 1 == 2 --> false
not 1 --> false
-- so it's
false == 2

So you’re basically doing (not ot) == player, in Lua, the not operator binds more tightly than the == operator. Use ot ~= player instead.

Already tried that, still doesn’t works

When I try that, this happens:

	if (ot == player) then
				inarea = true
				print('i')
				player.PlayerGui.Game.FrameWork.safezone.Visible = true
			elseif (ot ~= player) then
				 	inarea = false
				player.PlayerGui.Game.FrameWork.safezone.Visible = false
				print('o')
		end

o (x3)

i

o (x10)

i

o (x9)

i

o (x3)

i

o

i (x2)

o

i

o (x3)

i

o (x10)

i

o (x9)

i

o (x3)

i

o

i (x2)

o

i

o (x3)

i

o (x10)

i

o (x5)

Any idea what’s causing this? :confused:

Because it turns on once for every part in the player, and then off for every part that is not.
You want to do something like this instead

local playerfound = false
for blah in pairs(region stuff) do
   if players:getplayerfromblah(blah) == player then
      playerfound = true
   end
end
guithing.visible = playerfound

Hey, it works, but how can I make it dissapear?

	if game.Players:GetPlayerFromCharacter(v.Parent) == player then

	
		
				inarea = true
				
				player.PlayerGui.Game.FrameWork.safezone.Visible = true
		elseif (game.Players:GetPlayerFromCharacter(v.Parent) ~= player) or (game.Players:GetPlayerFromCharacter(v.Parent) == nil) then
			inarea = false
				
				player.PlayerGui.Game.FrameWork.safezone.Visible = false
		end

I tried ‘else’ but still didn’t work