Color changing physgun for certain usergroups

Hello. I am using this code at the moment to restrict color changing physgun to admins, but I would like to edit the code to restrict it to certain usergroups. I am not sure if customcheck would work here, and if, how.



timer.Create( "PhysColor", 0.001, 0, function()

	for id, ply in pairs( player.GetAll() ) do
	
		if ( !ply:IsAdmin() ) then continue end
		
		local col = HSVToColor( CurTime() % 6 * 60, 1, 1 )
		ply:SetWeaponColor( Vector( col.r / 255, col.g / 255, col.b / 255 ) )
		
	end
	
end )


Thanks for any help.

For your if statement you could use this instead.


 if ( ply:IsAdmin() ) then 
-- do stuff
end

I guess you don’t understand what I need. I need to edit this code so the physgun changes colors for VIPs and Admins only.

And I need $16 by tomorrow for my next car payment. But the world doesn’t just give us things, does it? You’re gonna have to work instead of just telling people what you “need”. Thankfully there are friendly and helpful people all over the place, so here’s what you need.

Take a look at what Winter posted:
[lua]
if ( ply:IsAdmin() ) then
– do stuff
end
[/lua]
Reading that, what do you think passes that statement? If you said “players that are admin,” then you’re correct! That statement will only pass players that are admin. However, that’s not what you quite need. So, moving forward from that, Garry’s Mod doesn’t have a function that simply detects if a user is VIP as it does for admin and superadmin. So we’re gonna have to come up with our own check to allow that statement to pass VIP’s as well.

Player:GetUserGroup is a function that returns a player’s usergroup. This is how we’ll be able to check the group of the player. So if you’d like to check if the player’s usergroup is VIP, you’d simply do the following:
[lua]
ply:GetUserGroup() == “vip”
[/lua]
If you’d like more than just VIP’s and admins to pass that statement, instead of just adding a bunch of “or usergroup” statements, you could simplify it by putting all of the usergroups you’d like into a local table. Afterwards, using

table.HasValue you’ll be able to simply check if the player’s usergroup is one in the table.

If you have no idea what the fuck any of the above is:
Click this if you don’t want to learn and would just like to be given the code

Have a beautiful day.

[lua]
local GroupLookup =
{
[ “vip” ] = true,
–[ “Add more groups like this” ] = true,
}
timer.Create( “PhysColor”, 0.001, 0, function()

for id, ply in pairs( player.GetAll() ) do

	if ( !ply:IsAdmin() ) and not GroupLookup[ ply:GetUserGroup() ] then continue end
	
	local col = HSVToColor( CurTime() % 6 * 60, 1, 1 )
	ply:SetWeaponColor( Vector( col.r / 255, col.g / 255, col.b / 255 ) )
	
end

end )
[/lua]

oops i didnt refresh the page.
both his and mine works, but I would suggest using mine instead as youre calling this very often and my code has a direct lookup

Cheers!