HUD help

So in my client side HUD file I’m trying to reference ply but when I do this I’m just getting an error saying ply is nil. Can someone please explain to me how calling ply works.

[lua]
function DrawPlayerInfo(ply)
local pos = ply:EyePos()
pos.z = pos.z + 15
pos = pos:ToScreen()
pos.y = pos.y - 60

draw.DrawText( ply:Nick(), "PlayerInfo", pos.x, pos.y + 10, Color(200, 0, 0, 255))

end
[/lua]

You need to pass the player object to DrawPlayerInfo when you call it.

Do you mean using the FindMetaTable?

Can you show us where you are calling this function from/how? You’ve defined a method that says a variable named “ply” is going to be provided into it but have not shown us the code doing that call.

Sure

[lua]

local plyMeta = FindMetaTable(“Player”)

function plyMeta:DrawPlayerInfo(ply)
local pos = self:EyePos()
pos.z = pos.z + 15
pos = pos:ToScreen()
pos.y = pos.y - 60

draw.DrawText( ply:Nick(), "PlayerInfo", pos.x, pos.y + 10, Color(200, 0, 0, 255))

end

[/lua]

That’s just the function definition, not where you’re calling it from.

Is this supposed to draw the player you call player:DrawPlayerInfo() on, or is it supposed to draw the player from the argument (so, player:DrawPlayerInfo(playerToDraw) ?)

Your current implementation is that I have to call DrawPlayerInfo on a player and pass whatever player I want to draw into the arguments.

Okay so I did some research and I kinda understand that I actually need to declare my functions before I can pass them. Thanks for your help I figured it out now :slight_smile:

https://wiki.garrysmod.com/page/Global/FindMetaTable this page really helped.