DrawWorldModel error

I am trying to make a gun that makes you invisible when you click, so to hide the weapon, I am trying to use


It works, but it always gives me an error. The error always says:

attempt to call method 'DrawWorldModel' (a nil value)

What can I use to properly use the DrawWorldModel without errors?


Do an IsValid check on the owner.

We could help better if you post more context as to where the code is called from.

There’s a bit more to do when setting someone to invisible.

In addition to PrePlayerDraw ( return true to hide the player; this is clientside so it can’t be trusted as the only thing to hide the player ): https://dl.dropboxusercontent.com/u/26074909/tutoring/gm_functions_and_hooks/gm_preplayerdraw_making_players_invisible.lua.html

You’d need the following calls:

_p:SetRenderMode( RENDERMODE_NORMAL );

// Invisible
_p:SetColor( Color( 0, 0, 0, 0 ) );
_p:SetNoDraw( true );
_p:DrawWorldModel( false );

// Visible
_p:SetColor( Color( 255, 255, 255, 255 ) )
_p:SetNoDraw( false );
_p:DrawWorldModel( true );

That’s the thing, it works great single player, but when I bring it to multiplayer, anytime DrawWorldModel (true/false) is run, it says it is a nil value… It works, which is the weird thing, but it spams console. This is sort of a cloak, so I just set the material of the body to heatwave, but anytime I try to set the weapon material to heatwave, it does weird things.

Those functions need to be ran serverside ( except for PrePlayerDraw ).

The reason it works in single-player / listen-server is because client and server are the same meaning the code merges and some can even be overwritten ( which is why it isn’t a good idea to dev on a listen-server ) leaving you with unknown effects when run on a dedicated server.

Setting up a local SRCDS is EASY. On top of that, if your client crashes, you don’t need the server part to re-load. If the server crashes, you don’t need to reload the client. So much easier to debug that way.

Here’s how to set up a local SRCDS ( not all of these are required, just like you don’t need to mount all games; but do force-directory as mount.cfg doesn’t like the names of the games when they’re left to install in other directories ):

Server: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

FastDL: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/fastdl_setup_instructions.lua.html

Recursive Resource Loader: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_downloads_using_recursive_resource_system.lua.html

I appreciate your response, but I know how to set up an SRCDS server. I do normally test on just the regular server, but I have no idea how to make the DrawWorldModel() to work without running errors… You said to run it server side, but how would I do that when I have

function SWEP:Holster()
self.Owner:DrawWorldModel( true )

everytime I holster it it says

 attempt to call method 'DrawWorldModel' (a nil value) 

Check self.Owner; it may be invalid / unset…

Use render mode alpha and set player alpha to 0 or use special materials

if IsValid( self.Owner ) then
local oldcl = self.Owner:GetColor()

WOO, I finally got a working version! Thankyou everyone for responding, and especially UnkN because you led me in the right direction! What I did was:

 	self.Owner:SetRenderMode( RENDERMODE_TRANSALPHA )
	self.Weapon:SetRenderMode( RENDERMODE_TRANSALPHA ) 

then I just used