ULX Physgun Groups Forced Physgun Color

I’m looking for someone to help or if you know some sort of code that make ULX ranks have different coloured physgun like e.g Trial Mod - Light blue Mod-green admin-dark blue, something like that and it stops clients from having there own color. I know the GM.SetWeapon color but that does it for everyone, this will probably need to work with DarkRP.

Start out by using this

You can store colors based on usergroup like this.



GroupPhysgunColors = {

	["user"] = Vector(1,0,0),
	["admin"] = Vector(0,1,0),
	["superadmin"] = Vector(0,0,1),

}
//You can retrieve the color like this ply:SetWeaponColor(GroupPhysgunColors[ply:GetUserGroup()])



I have edited this one and put it in DarkRP modules, can you fix it as it doesnt work.


--sh_phycolor.lua darkrpmodification-master/lua/modules

hook.Add("PlayerSpawn", "setphyscolor", function( ply )

    ply:SetWeaponColor(GroupPhysgunColors[ply:GetUserGroup()])
	
GroupPhysgunColors = {

	["owner"] = Vector(1,0,0),
	["admin"] = Vector(0,1,0),
	["superadmin"] = Vector(0,0,1),

}
--[[You can retrieve the color like this ply:SetWeaponColor(GroupPhysgunColors[ply:GetUserGroup()])--]]


end)

-- The vector for the color = COLOR / 255
-- for example: Color(125,90,25) = Vector(0.49, 0.35, 0.1)

Code reads top to bottom so if you’re attemping to index the table GroupPhysgunColors you’ll need to create that table first before you do anything with it. Also you want to place the table outside of playerspawn so it is not recreating each time the player is spawning.

You need to make a table…
I made one for ya, but the thing is, it is not pulling with the physgun when I made it. But it seems to pull a color.
So if you are modifying a Physgun SWEP, here.



local setphyscolor = 
{
--Group v[1]		--Vector v[2]
{"owner",		Vector( 0, 0, 0 ) },
{"superadmin",		Vector( 0, 0, 0 ) },
{"admin",		Vector( 0, 0, 0 ) },
{"moderator", 		Vector( 0, 0, 0 ) },
{"member",		Vector( 0, 0, 0 ) },
}

function PlayerSpawn( ply )
	if ply:IsValid() then
		for k,v in pairs(setphyscolor) do
			if ply:IsUserGroup(v[1]) then
				ply:SetWeaponColor(v[2])
			end
		end
	end
end


The other reason it doesn’t work from looking at what you accomplished…
The variable, “setphyscolor” was never defined in your hook. Also be sure to read over this: https://wiki.garrysmod.com/page/Player/SetWeaponColor
Not sure why you are running it as a hook, but I modified the hook script you made also in case you want to use this instead…



local setphyscolor = 
{
--Group v[1]		--Vector v[2]
{"owner",		Vector( 0, 0, 0 ) },
{"superadmin",		Vector( 0, 0, 0 ) },
{"admin",		Vector( 0, 0, 0 ) },
{"moderator", 		Vector( 0, 0, 0 ) },
{"member",		Vector( 0, 0, 0 ) },
}

hook.Add("PlayerSpawn", "setphyscolor", function( ply )
	if ply:IsValid() then
		for k,v in pairs(setphyscolor) do
			if ply:IsUserGroup(v[1]) then
				ply:SetWeaponColor(v[2])
			end
		end
	end
end)


The groups can be changed out to your ULX Groups.
If you have any further questions, lemme know ._. I’m still a newb at SWEPs ;w;