How to Make Entity Spawn Where Player is Looking At

Hello, I’m currently making a gamemode and have a question. I am trying to make an entity spawn where the player looks as it will be an entity the player buys.
I have tried looking into other gamemode codes that have this to see IF I could figure it out but I am at a total loss.
Heres the code:

//spawn profitables
function BuyBronzePrinter( ply, cmd )	
	if ply:GetMoney() >= 2000 then
        ply:TakeMoney( 2000 )
		local pos = ply:GetPos()
		bronze:SetPos(Vector(_ply:GetEyeTrace().HitPos.x, _ply:GetEyeTrace().HitPos.y, _ply:GetPos().z + 10))
		bronze.Owner = ply
		bronze:SetColor(205, 127, 50, 100 )
		bronze:SetRenderMode( RENDERMODE_TRANSALPHA )
        ply:ChatPrint("You got a Bronze Printer!") --print "You got a x!" in the chat
        ply:ChatPrint("Not enough dosh for that one!")
concommand.Add("buybronzeprinter", BuyBronzePrinter)

I can not figure this out at all, if one of you could help me It would be greatly appreciated. Thanks!

bronze:SetPos(Vector(_ply:GetEyeTrace().HitPos.x, _ply:GetEyeTrace().HitPos.y, _ply:GetPos().z + 10))

Why do you do _ply instead of ply…
the underscore probably makes the language think you’re referencing a nil value. Just try ply.

It helps if you post any errors you’re seeing.

And no, not “probably” — it is nil.

  1. _ply is nil
  2. bronze should be a local variable
  3. localize the results of ply:GetEyeTrace() instead of calling it repeatedly
  4. if you look at the structure for trace results, you see it has a HitPos field. use that.
  5. you probably want to use a normal trace instead of ply:GetEyeTrace() unless you want players to be able to spawn money printers from across the map.

Again I was referencing code for the setpos, I’m not that familiar with Tracing so I’m really lost on how to handle this. I will look more into tracing. I’ll get back to you on those errors

Finally Figured it out, Thanks for stearing me in the right direction!