Spawning an entity on "DoClick" (Spawn Icons)

     SpawnIcon = vgui.Create("SpawnIcon", DFrame)
	  SpawnIcon:SetSize(40, 40)
      SpawnIcon:SetPos(15, 25)
      SpawnIcon:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
	  SpawnIcon.OnCursorEntered = function()--This is the function to use. 
      print("We're hovering the icon")--Print a message to the console
    return false --Return false to remove the hovereffect
	  SpawnIcon.DoClick = function()
	  local canPos = Local.Entity:GetPos() -- **Line 47**
	  local can = ents.Create("can")
		can:SetPos(Vector(canPos.x,canPos.y,canPos.z - 1))

The error line is “entities/machine/cl_init.lua:47: attempt to index global ‘Local’ (a nil value)”

If someone could kindly explain what I am doing wrong I would appreciate it :slight_smile:

I dont think you need the “Local.”

Local is a nil value.


That is what the error says.

Oh wait, are you trying to get the positioning of the entity, before it’s created?


@ MakeR, I’m not sure what that means.

Nil = nothing, right?

Looks like he is trying to spawn a can at a position of another entity. You can’t spawn entities clientside.

Obviously you can use gm_spawn, but that isn’t spawning the entity clientside. That is using a console command to tell the server to do it.

But that is the way to go.


Cheers for your help guys; figured out I was trying to spawn an entity client side, fixed it with a concommand.