Bad key to string index (number expected, got string)

Very new to LUA here, it’s telling me my problem but I’m a bit clueless.

Here’s the problematic code:

function spawn_melon( ply, tr )
	local size = math.random( 16, 48 )
	local SpawnPos = tr.HitPos + tr.HitNormal * size
	local melon = ents.Create( "prop_physics" )
	melon:SetModel( "models/props_junk/watermelon01.mdl" )
	melon:SetPos( SpawnPos )
concommand.Add("spawn_melon", spawn_melon)

And the error (also in title)

[ERROR] gamemodes/gamemodename/gamemode/init.lua:146: bad key to string index (number expected, got string)

Any pointers are appreciated. :slight_smile:

There’s no such argument as tr in console commands. Arguments are:
Player - executor of command
Command - Executed command
Args - Arguments passed to the command

You want to do something like this:

local tr = ply:GetEyeTrace()

That worked straight off the bat.

Thanks for the help!