Global ply(nil value)

Hey ,
I am having some problems with my Menu i’ve created for my gamemode.
I get this Error

War!/gamemode/cl_init.lua:18: attempt to index global ‘ply’ (a nil value)

Here is the line.

local tr = ply:GetEyeTrace() // LINE 18!
local prop = ents.Create(“prop_physics”)
prop:SetPos(tr.HitPos)
prop:SetModel(“models/props_c17/concrete_barrier001a.mdl”)
prop:Activate()
prop:Spawn()

You’re doing that in your cl_init which is client side. Put it in your init.lua instead.

Forgot that, Thank you!

Okay Now thats cleared. NVM.

snip

Okay, now that the menu works. It spawns the prop where the mouse is. How do i change it so it spawns in front of me?

You need to do the spawning serverside in a console command, then call it on the client.

[Concommand.Add

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Concommand.Add)
[RunConsoleCommand

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.RunConsoleCommand)

Then call the function by a command…

Also on the client you should be using LocalPlayer(), not ply.

[editline]07:13PM[/editline]

Automerge…

Where do i put the concommand for spawning the prop. In what File?

init.lua

Would this be right ?

function PropSpawnBarrier()
local td = {}
td.start = ply:GetShootPos()
td.endpos = ply:GetShootPos() + ply:GetAimVector()*256
td.fliter = MASK_NPCWORLDSTATIC
local tr = util.TraceLine(td)

local prop = ents.Create(“prop_physics”)
prop:SetPos(tr.HitPos)
prop:SetModel(“models/props_c17/concrete_barrier001a.mdl”)
prop:Spawn()
prop:Activate()
prop:SetNWString(“Owner”,ply:Name())
end
concommand.Add( “SpawnBarrier”, PropSpawnBarrier )

Almost.
[lua]local function PropSpawnBarrier(ply, cmd, args)
local prop = ents.Create(“prop_physics”)
local tr = ply:GetEyeTrace();
prop:SetPos(tr.HitPos)
prop:SetModel(“models/props_c17/concrete_barrier001a.mdl”)
prop:Spawn()
prop:Activate()
prop:SetNWString(“Owner”,ply:Name())
end
concommand.Add( “SpawnBarrier”, PropSpawnBarrier ) [/lua]

Thanks Nullpoint and Horsey i got it to work perfectly with your help ;D!