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
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
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