• tostring() returning nil when attempting to convert userdata (weapon) to string.
    2 replies, posted
for _,npc in pairs(ents.GetAll()) do  if npc:IsNPC() then  local weapon = npc:GetActiveWeapon() if IsValid( weapon ) then local weapon_drop = ents.Create(tostring( weapon )) weapon_drop:SetPos(weapon:GetPos()) weapon_drop:SetAngles(weapon:GetAngles()) weapon_drop:Spawn() end end end I'm attempting to spawn a weapon entity, copying the entity classname the NPC holds, but there's a slight problem. tostring() only returns nil from the userdata variable. I searched up the Wiki for any alternatives but no such luck. Can anyone know what to do? I'm already a bit frustrated at this.
:GetClass()
Dang, was only focused on strings. Never thought to check more than that.
Sorry, you need to Log In to post a reply to this thread.