Can't use Remove() on an entity... ( attempt to call global ' Remove' (a nil value)
6 replies, posted
I've declared the entity name way above so it should be within the lexical scope.
Then I actually create the entity within a netlibrary function (but it's not local so that should be fine, unless my understanding is wrong)
When I try another netlibrary function below, this time to entityname:Remove(), it throws that error. What am I missing here? They should be within scope if I declared the name earlier, unless somehow net.Receive is throwing something off...
Do you have some code to show us?
[QUOTE=Dizla;49105249]Do you have some code to show us?[/QUOTE]
[CODE]truck45crew_phase1 = ents.Create("npc_citizen")
util.AddNetworkString("truck45_establish_rit")
net.Receive("truck45_establish_rit", function()
truck45crew_phase1 = ents.Create("npc_citizen")
truck45crew_phase1:SetModel("models/npc/cdc_soldier_npc.mdl")
truck45crew_phase1:SetPos(Vector(-8597,-13247,100))
truck45crew_phase1:Spawn()
local truck45crew_phase1 = ents.Create("npc_citizen")
truck45crew_phase1:SetModel("models/npc/cdc_soldier_npc.mdl")
truck45crew_phase1:SetPos(Vector(-8567,-13247,100))
truck45crew_phase1:Spawn()
local truck45crew_phase1 = ents.Create("npc_citizen")
truck45crew_phase1:SetModel("models/npc/cdc_soldier_npc.mdl")
truck45crew_phase1:SetPos(Vector(-8587,-13207,100))
truck45crew_phase1:Spawn()
Entity(1) :EmitSound("truck45/establish_rit.mp3",100,100,1,CHAN_AUTO)
end)
end)
util.AddNetworkString("squad44_establish_rit")
net.Receive("squad44_establish_rit", function()
//ents.FindByClass( "npc_citizen" )[1]:Remove() // not sure but this line seemed completely crash gmod ...
truck45crew_phase1:Remove()
end)[/CODE]
Check if the entity is valid, otherwise you can't remove a null
You have multiple entities referenced as one variable, which obviously won't work, only the last npc_citizen created would be stored to "truck45crew_phase1" variable.
Also you might want to replace "truck45crew_phase1 = ents.Create("npc_citizen")" with something like "truck45crew_phase1 = NULL" on the very first line.
Try firing Kill
[QUOTE=Potatofactory;49108553]Try firing Kill[/QUOTE]
Won't change a thing.
Sorry, you need to Log In to post a reply to this thread.