Hello, I've been having this issue ALL day. This is returning an error saying tried to use a NULL entity! I don't know why.
Here's the error in console:
[CODE]
[ERROR] gamemodes/terrortown/gamemode/ent_replace.lua:125: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. ReplaceWeapons - gamemodes/terrortown/gamemode/ent_replace.lua:125
3. ReplaceEntities - gamemodes/terrortown/gamemode/ent_replace.lua:159
4. unknown - gamemodes/terrortown/gamemode/init.lua:388
[ERROR] gamemodes/terrortown/gamemode/ent_replace.lua:125: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. ReplaceWeapons - gamemodes/terrortown/gamemode/ent_replace.lua:125
3. ReplaceEntities - gamemodes/terrortown/gamemode/ent_replace.lua:159
4. unknown - gamemodes/terrortown/gamemode/init.lua:388
[/CODE]
Line 125 is [CODE]newweps:Activate()[/CODE].
Here's my code:
[CODE]local function ReplaceWeapons()
for _, ent in pairs(table.Merge(ents.FindByClass("weapon_ttt*"), ents.FindByClass("weapon_zm*"))) do
if ValidEntity(ent) then
local weaponpos = ent:GetPos()
randomnewweps = {}
randomnewweps[1]="weapon_cstm_pistol_deagle"
randomnewweps[2]="weapon_cstm_pistol_fiveseven"
randomnewweps[3]="weapon_cstm_pistol_glock"
randomnewweps[4]="weapon_cstm_pistol_p228"
randomnewweps[5]="weapon_cstm_rif_ak47"
randomnewweps[6]="weapon_cstm_rif_famas"
randomnewweps[7]="weapon_cstm_rif_m249"
randomnewweps[8]="weapon_cstm_shotgun_shotgun"
randomnewweps[9]="weapon_cstm_smg_mac10"
randomnewweps[10]="weapon_cstm_smg_p90"
randomnewweps[11]="weapon_cstm_smg_tmp"
randomnewweps[12]="weapon_cstm_smg_ump45"
randomnewweps[13]="weapon_cstm_snip_rifle"
randomnewweps[14]="weapon_cstm_sniper_aug"
randomnewweps[15]="weapon_cstm_sniper_sg550"
randomnewweps[16]="weapon_cstm_sniper_sg552"
if ValidEntity(ent) then
local newweps = ents.Create(table.Random(randomnewweps))
newweps:SetPos(weaponpos)
newweps:Spawn()
newweps:Activate()
print(tostring(newweps).. " successfully replaced " ..tostring(ent))
ent:Remove()
end
end
end
end[/CODE]
print newweps I imagine it is not able to create any of the weapon entities since they don't exist
The weapon entites do exist, but i don't know why it's giving this error.
[QUOTE=sackcreator54;42023415]The weapon entites do exist, but i don't know why it's giving this error.[/QUOTE]
print newweps and confirm it then