Script Causes Default Player Skins to Bug Out

So I’m trying to update and work on my random weapon spawn script but every time I upload it to test all the default players skins become grey blobs for some reason. No error is given and the script appears to work just fine except for that bug. I did some research but I can’t find anything about this specific problem. If you want to know what it looks like it’s the default skin shown in the popular pointshop addon.


/*
    name:           armory
    description:    give a random default weapon to players when they spawn as well as a message alerting them what they spawned with
    author:         mickers
    email:          mickersgaming@gmail.com
    date:           6/03/2013
*/

if SERVER then
    AddCSLuaFile("armory.lua")
end

// table for primaries, secondaries, and grenades
// with sub categories type, name, ammo, clipsize, and displayname
local weapons = {
    {["type"]="primary", ["name"]="weapon_zm_shotgun", ["ammo"]="Buckshot", ["clipsize"]=24, ["displayname"]="Shotgun"},
    {["type"]="primary", ["name"]="weapon_ttt_m16", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="M16"},
    {["type"]="primary", ["name"]="weapon_zm_mac10", ["ammo"]="SMG1", ["clipsize"]=60, ["displayname"]="MAC10"},
    {["type"]="primary", ["name"]="weapon_zm_rifle", ["ammo"]="357", ["clipsize"]=20, ["displayname"]="Scout"},
    {["type"]="primary", ["name"]="weapon_zm_sledge", ["ammo"]="", ["clipsize"]="", ["displayname"]="H.U.G.E"},
    
    {["type"]="secondary", ["name"]="weapon_zm_revolver", ["ammo"]="AlyxGun", ["clipsize"]=36, ["displayname"]="Deagle"},
    {["type"]="secondary", ["name"]="weapon_zm_pistol", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="Pistol"},
    {["type"]="secondary", ["name"]="weapon_ttt_glock", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="Glock"},
    
    {["type"]="grenade", ["name"]="weapon_tttbasegrenade", ["displayname"]="Discombobulator"},
    {["type"]="grenade", ["name"]="weapon_zm_molotov", ["displayname"]="Incindiary Grenade"},
    {["type"]="grenade", ["name"]="weapon_ttt_smokegrenade", ["displayname"]="Smoke Grenade"}
}

// spawns players with a primary, secondary and grenade
hook.Add("PlayerLoadout", "GiveWeapon", function(ply)
    // select random weapons
    local primaryweapon = table.Random(weapons.primary)
    local secondaryweapon = table.Random(weapons.secondary)
    local grenade = table.Random(weapons.grenade)
    
    // arm player
    ply:Give(primaryweapon.name)
    ply:Give(secondaryweapon.name)
    ply:Give(grenade.name)
    
    // load guns
    // if primary is m16 and pistol uses the same ammo then
    if primaryweapon.ammo == secondaryweapon.ammo then
        ply:GiveAmmo(primaryweapon.clipsize, primaryweapon.ammo)
    // if primary is the huge
    elseif primaryweapon.ammo == "" then
        ply:GiveAmmo(secondaryweapon.clipsize, secondaryweapon.ammo)
    else
        ply:GiveAmmo(primaryweapon.clipsize, primaryweapon.ammo)
        ply:GiveAmmo(secondaryweapon.clipsize, secondaryweapon.ammo)
    end
    
     // notify player which weapons he/she received
    ply:ChatPrint("You have been randomly given a "..primaryweapon.displayname.." a "..secondaryweapon.displayname.." and a "..grenade.displayname.." by the base cat god.".."

Happy traiting!")

end)

I only made 2 changes to the previously working code. I added a displayname field and used table.random() instead of math.random(). I don’t know why that would make such a big deal.

Are you sure this is caused by the script you provided?

100% as soon as I delete the script from the server and reload the map the problem goes away.

Well weapons.Primary doesn’t exist so the error is causing PlayerSpawn not to be called (where your player model is set). Also weapons is a library I think so you might want to use a different name for the table.

table.Random(weapons.Primary)

Review your table structure.

Thanks MyBigBoner.cc.

Edit:

Working code:


/*
    name:           armory
    description:    give a random default weapon to players when they spawn as well as a message alerting them what they spawned with
    author:         mickers
    email:          mickersgaming@gmail.com
    date:           6/03/2013
*/

if SERVER then
    AddCSLuaFile("armory.lua")
end

// table of weapons containing primaries, secondaries, and grenades
// with sub categories type, name, ammo, clipsize, and displayname
local playerweapons = {
        primary = {
            {["name"]="weapon_zm_shotgun", ["ammo"]="Buckshot", ["clipsize"]=24, ["displayname"]="Shotgun"},
            {["name"]="weapon_ttt_m16", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="M16"},
            {["name"]="weapon_zm_mac10", ["ammo"]="SMG1", ["clipsize"]=60, ["displayname"]="MAC10"},
            {["name"]="weapon_zm_rifle", ["ammo"]="357", ["clipsize"]=20, ["displayname"]="Scout"},
            {["name"]="weapon_zm_sledge", ["ammo"]="", ["clipsize"]="", ["displayname"]="H.U.G.E"}
        },
        
        secondary = {
            {["name"]="weapon_zm_revolver", ["ammo"]="AlyxGun", ["clipsize"]=36, ["displayname"]="Deagle"},
            {["name"]="weapon_zm_pistol", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="Pistol"},
            {["name"]="weapon_ttt_glock", ["ammo"]="Pistol", ["clipsize"]=60, ["displayname"]="Glock"}
        },
        
        grenade = {
            {["name"]="weapon_tttbasegrenade", ["displayname"]="Discombobulator"},
            {["name"]="weapon_zm_molotov", ["displayname"]="Incindiary Grenade"},
            {["name"]="weapon_ttt_smokegrenade", ["displayname"]="Smoke Grenade"}
        }
    }

// spawns players with a primary, secondary and grenade
hook.Add("PlayerLoadout", "GiveWeapon", function(ply)
    // select random weapons
    local primaryweapon = table.Random(playerweapons.primary)
    local secondaryweapon = table.Random(playerweapons.secondary)
    local grenade = table.Random(playerweapons.grenade)
    
    // arm player
    ply:Give(primaryweapon.name)
    ply:Give(secondaryweapon.name)
    ply:Give(grenade.name)
    
    // load guns
    // if primary is m16 and pistol uses the same ammo then
    if primaryweapon.ammo == secondaryweapon.ammo then
        ply:GiveAmmo(primaryweapon.clipsize, primaryweapon.ammo)
    // if primary is the huge
    elseif primaryweapon.ammo == "" then
        ply:GiveAmmo(secondaryweapon.clipsize, secondaryweapon.ammo)
    else
        ply:GiveAmmo(primaryweapon.clipsize, primaryweapon.ammo)
        ply:GiveAmmo(secondaryweapon.clipsize, secondaryweapon.ammo)
    end
    
     // notify player which weapons he/she received
    ply:ChatPrint("You have been randomly given a "..primaryweapon.displayname.." a "..secondaryweapon.displayname.." and a "..grenade.displayname.." by the base cat god.".."

Happy traiting!")

end)

Thanks again!