ents.CreateClientProp returns a NULL entity

Here’s the code that is run when a packet is received (with the net library):


local ent = ents.CreateClientProp("models/REDACTED.mdl");
ent:Spawn();
GAMEMODE.associatedModels[net.ReadString() --[[ the steam id --]]] = ent;

When I later print the table, it says that the client entity is a NULL one.

GAMEMODE.associatedModels might be shared or serverside. Are you sure you’re not reading the entity or printing it severside?

Nope, I initialize it in cl_init.lua.

Is this file included?

Could you post the code where you print the table? Sorry, just making sure.

Actually nvm, GM is global my bad, but if you include it you can use just a table? Oh and GAMEMODE.associatedModel looks like this correct? …


GM.associatedModel = { STEAM_0:1:80425272 = "models/player/something.mdl" }

Now if I am correct, tell me what happens after you use = ent; as that means from now on a model is the entity now? unless your using the steamid as a reference?



{ STEAM_0:1:80425272 = "models/player/something.mdl" }


That steam ID won’t work unless it’s a string



{ "STEAM_0:1:80425272" = "models/player/something.mdl" }


[editline]17th August 2017[/editline]

Sorry, I’m stupid, that probably isn’t at all what you meant

It’s roughly this:


function GM:PostPlayerDraw(ply)
    -- do some things with the model
    PrintTable(self.associatedModels);
end

Yes, the Steam ID is the identifier for the model.

This really isn’t enough “CODE” to help me understand, all I can see is you create the table on post player draw? But why use PostPlayerDraw? Why don’t you just use a think function and grab the model?

I plan on doing shit with the model like moving it around constantly which should be done on PostPlayerDraw.

Can you show us the full thing where the table is being defined?

[editline]17th August 2017[/editline]

All I see is your code saying: steamid = ent not steamid = model, and why dont you just try using a sompe globaled table?

[editline]17th August 2017[/editline]

All I see is your code saying: steamid = ent not steamid = model, and why dont you just try using a sompe globaled table?

The main post above shows me making the entity.
I initialize the table outside of any function definition:


include("shared.lua")

local font = surface.CreateFont("PlayerNameFont", {
	font = "Trebuchet MS",
	extended = true,
	size = 30,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotery = false,
	shadow = false,
	additive = false,
	outline = false
});

GM.associatedModels = {};

-- functions here

Take away the GM. and self. stuff and just call it associatedModels

That is not the issue, since GAMEMODE.associatedModels is not nil, but rather a value in it.

EDIT not even that. The value is not nil, but a NULL entity

I precached the model and replaced the call with a call to ClientsideModel, and now it works.