Is this the right way to restrict spawn and context menu to ranks?



if SANDBOX:SpawnMenuOpen() then
	function checkULX(ply)
		if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
			return true
			else return false
		end
	end
end,
})

if GM:ContextMenuOpen() then
	function checkULX(ply)
		if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
			return true
			else return false
		end
	end
end,
})



if SANDBOX:SpawnMenuOpen() then --SANDBOX is nil, it will cause an error
	function checkULX(ply) --This function is never ran
		if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
			return true
			else return false
		end
	end
end, --There is no reason for this comma to be here, it will cause an error
}) --There is no reason for these to be here, it will cause an error

if GM:ContextMenuOpen() then --Unless you're editing gamemode files, GM will be nil, it will cause an error
	function checkULX(ply) --This is overwriting the function you made earlier
		if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
			return true
			else return false
		end
	end
end, --No reason for this comma to be here either, it will cause an error
}) --No reason for these to be here either, it will cause an error

I commented some the problems, and you should probably give these a read:

hook.Add

SANDBOX:SpawnMenuOpen

GM:ContextMenuOpen

Also, this will only prevent players from opening the spawnmenu, it will not prevent them from using console commands like gm_spawn or other methods to spawn things without the spawnmenu. If you want to prevent that as well, use these:

SANDBOX:PlayerSpawnNPC

SANDBOX:PlayerSpawnObject

SANDBOX:PlayerSpawnProp

SANDBOX:PlayerSpawnRagdoll

SANDBOX:PlayerSpawnSENT

SANDBOX:PlayerSpawnSWEP

SANDBOX:PlayerSpawnVehicle

And for preventing context menu things:

SANDBOX:CanProperty

Don’t forget to make the functions local, as from looking at your code you aren’t using them anywhere else.

Sorry, I just started trying Lua yesterday :confused:

A friend gave me this :smiley:



hook.Add("PlayerSpawnObject", "gay", function(ply, model, skin)
	if !ply:IsSuperAdmin() then return false end
end)

hook.Add( "CanProperty", "gay2", function( ply, property, ent )
 	if !ply:SuperAdmin() then return false end
end )


someone close this thread please

Upper left conner of the OP > Press that and it will lock