Weapon can't spawn with custom made spawn icon

My dumb ass managed to single-handedly revive Facepunch forums with my retarded questions.

Issue

attempt to index global ‘surface’ (a nil value)

SWEP.WepSelectIcon = surface.GetTextureID(“vgui/entities/pew-gun”)

After that I have SWEP.Initialize and all that other junk.
I see this works on other SWEP’s but it simply doesent on mine, the spawn icon shows up, but it doesen’t allow me to spawn the gun, other guns work perfectly fine.
SWEP print name is “Pew gun” if that has to do with anything.
I have another SWEP with the same material under a diffrent name, if that means anything. ( seperate addon)

Wrap your SWEP.WepSelectIcon in a if CLIENT then block like so:

if CLIENT then
	SWEP.WepSelectIcon = surface.GetTextureID("vgui/entities/pew-gun")
end

This is because the surface library doesn’t exist on the server, which also runs if your code is defined in a weapon’s shared.lua or a single file instead of a separate cl_init.lua

1 Like

Thank you VERY much!