Godmode in a specified space

Oh hello there, i’ve been trying to make a little script that toggles GodMode on a player if the player is located in a specified space, like the spawn on flatgrass. Can anybody make a fast script? I believe its quite easy, but i am not thinking the right way. You would be my hero.

I could actually use this too if this would be made :smiley:

I’m going to learn lua further soon, cuz I took a long ass break and I lost alot of the knowledge =)
So yeah, this could be handy :stuck_out_tongue:

Next = 0;
local meta = FindMetaTable( "Player" );

function meta:IsInBox( min, max )
	local Result = ents.FindInBox( min, max );
	for k,v in pairs( Result ) do
		if( v && ValidEntity( v ) && v:IsPlayer() ) then
			return true;
			return false;

function Check()
    if( CurTime() >= Next ) then
		for k,v in pairs( player.GetAll() ) do
			if( ValidEntity( v ) ) then
				if( v:IsInBox( Vector( INSERT X,Y,Z ), Vector( INSERT X,Y,Z ) ) ) then
					v:SetNWBool( "TakeDamage", false );
					v:SetNWBool( "TakeDamage", true );
        Next = CurTime() + 1;
hook.Add("Think", "Check", Check)

function playershouldtakedamage(victim, attacker)
	if( victim:GetNWBool( "TakeDamage" ) == false ) then return false; end
hook.Add( "PlayerShouldTakeDamage", "playershouldtakedamage", playershouldtakedamage)

There ya go, not sure how efficient this script is or anything when there’s like 30 players, but I guess you’ll find out. :stuck_out_tongue:
Save as godmode.lua inside garrysmod/lua/autorun/server, if the folders doesn’t exist, just create them.

All you have to do it put in the 2 vectors.

how do I find the vectors? (X,Y,Z)

In the console, type


Thanks Jamie