StripWeapons()

I need help with this, I’ve got this code;



function loadPlayer( ply )
	if ply:IsAdmin() then
		ply:StripWeapons()
		ply:Give("weapon_physgun")
	else
		ply:Give("weapon_crowbar")
		ply:Give("weapon_physgun")
		ply:StripWeapons()
	end
end


However the issue I’m experiencing is that when players spawn, their weapons aren’t stripped, and I’m aware that there isn’t a hook present, but I’ve added one. This is the code for it as well in case;



hook.Add("PlayerSpawn", "Give Guns", loadPlayer)


Try something like this.
[lua]
local function GiveWeapons( ply )
if ( ply:IsAdmin() ) then
ply:Give(“weapon_physgun”) --Use ply:Give to give admin their weapons here
ply:SelectWeapon( “weapon_physgun” ) --Use ply:SelectWeapon to set the weapon admins have out when they spawn
else
ply:Give(“weapon_physgun”) --Use ply:Give to give users their weapons here
ply:SelectWeapon( “weapon_physgun” ) --Use ply:SelectWeapon to set the weapon users have out when they spawn
end
return true
end
hook.Add( “PlayerLoadout”, “GiveWeapons”, GiveWeapons )
[/lua]

[lua]
local function LoadPlayer(pl)
if ply:IsAdmin() then
pl:StripWeapons()
pl:RemoveAllAmmo()
pl:Give(“weapon_physgun”)
else
pl:StripWeapons()
pl:RemoveAllAmmo()
pl:Give(“weapon_crowbar”)
pl:Give(“weapon_physgun”)
end
end
hook.Add(“PlayerSpawn”, “Give_Guns”, LoadPlayer)
[/lua]
That should work, I think your problem was you had a space between ‘Give Guns’, otherwise I’m not sure what else would cause it to not work everything looks fine.

Awh you beat me to it.

I had a problem with the “PlayerSpawn” and StripWeapons() myself. My solution?
Put all the code in a secondary function and call that with a timer from the LoadPlayer function. Works with 0.01 delay.