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
	  SpawnIcon:SetToolTip("Cola")
    return false --Return false to remove the hovereffect
      end
	  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))
		can:Spawn()

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.

[editline]12:54PM[/editline]

That is what the error says.

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

[editline]01:55PM[/editline]

@ 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.

:eng101:

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