Restricting area with FindInBox and SetPos

I’m having a struggle trying to make a certain area accessible to the moderator/admin/superadmin groups only, because for whatever reason it completely ignores the groups part and teleports you out of the area regardless of your group.
This is the code:



function ResArea ()
    local min = Vector( -258.90469360352, -2684.5952148438, 33.21267700195 )
    local max = Vector( 325.92169189453, -2274.291015625, 537.71624755859 )
    local pos = Vector( -4.342023, -2107.945068, 182.823654 )


    for k, v in pairs(ents.FindInBox( Vector(min), Vector(max) )) do
        if v:IsPlayer() and v:IsValid() then
		if( v:IsUserGroup() == "Moderator" or v:IsUserGroup() == "admin" or v:IsUserGroup() == "superadmin") then
			v:PrintMessage( HUD_PRINTCENTER, "Welcome, " .. v:Nick() .. "!")
		else
			v:PrintMessage( HUD_PRINTCENTER, "You can't enter in this area")
			v:SetPos(Vector(pos))
		end
	end
    end
end
hook.Add('Think', 'RestrictedArea', ResArea);


Thanks in advance.

Player:GetUserGroup

Player:IsUserGroup
You don’t have to define vectors in Think hook and you are doing Vector(Vector(…))

Thanks Johnny.
I changed IsUserGroup to GetUserGroup and it works now. I don’t understand why though, what’s the big difference? The one checks if the player is in the specified group, the other retrieves the player’s specified group.

EDIT: Facepalm… Can’t see the forest because of trees, I’m so sorry.

is usergroup works like this



print(pl:IsUserGroup("Admin"))
> true -- or false


basically just checks whether the usergroup is equal to something specified, only returns true or fasle



print(pl:GetUserGroup())
> superadmin -- or whatever group they're in


unlike IsUserGroup, this returns the primary usergroup the pl is in as a string.

what you were doing previously was comparing a boolean to a string

Thanks ZeBull, I realised. Sometimes I’m so extremely blind, it clearly shows the difference on the Wiki page but I somehow miss it.

Thanks a lot to both of you!