Need help fetching information from SWEPS

Hello friends! I know almost nothing, I will admit, and so it is to you I come for help. I’m trying to fetch the AmmoType and DefaultClip size from a weapon, but I’m getting a couple of errors.

This is my script, currently:


local wep = 'weapon_ttt_walther'
local ammoamt = wep.Primary.DefaultClip
local ammotype = wep.Primary.AmmoType


hook.Add("PlayerSpawn", "playerspawnweapon", function(ply)
	GivePlayerWeapon(ply,wep)
end)

function GivePlayerWeapon(ply,wep)
	if not ply:IsSpec() then
		ply:Give(wep)
		ply:SelectWeapon(wep)
		ply:GiveAmmo( ammoamt, true )
	end
end

It spawns the weapon, but I get no additional ammo and it returns this error:


[ERROR] lua/autorun/weapons.lua:2: bad key to string index (number expected, got string)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:310
    3. unknown - lua/autorun/weapons.lua:2


Any help would be greatly appreciated!

You’ll want to use

weapons.Get;

[lua]
local wepClass = ‘weapon_ttt_walther’
local wep = weapons.Get(wepClass)
local ammoamt = wep.Primary.DefaultClip
local ammotype = wep.Primary.AmmoType
[/lua]

Thank you so much for pointing me in the right direction. After a little bit of fiddling, it works.