Error 'ply' (a nil value)

[lua]function ZZ.Openleft()

if( ply:Team() == 11 ) then   -- the line being affected


attempt to index global ‘ply’ (a nil value)

Can anyone tell me what this is or can break down the definition of the error for me?

Where are you defining ply?

The error is that ply is a variable, so you have to give it a value before using it.

How would I give it a value, any examples you can provide me with? I am REALLY a lua ‘newbie’.

Err, clientside?

local ply = LocaPlayer() ?

If that code is clientside then you can define ply like this:
[lua]local ply = LocalPlayer()[/lua] at the top of the fuction.

Thanks alot guys :D! I’ll try that out right now

Hey, can someone tell me some other stuff for local
like right now i have

attempt to call method ‘Team’ (a nil value)


So if you could give me a list or something so i can stop asking you all about how to do ‘local’ stuff
for the teams is it local team = LocalPlayerteam()

You’re getting that error because there are no meta functions for regular functions, that just wouldn’t make sense.

The variable LocalPlayer by itself refers to a function. What you want is what LocalPlayer returns, which is, the entity that is you. In order to do this you need to call LocalPlayer which you can do by using two parenthesis after the variable.

LocalPlayer --> Function, the variable itself

LocalPlayer( ) --> Entity, returned from the function

– Therefore:
local team = LocalPlayer( ):Team( )

Lua is a very object-oriented language :3 Especially with functions because they are treated as first-class variables.

The use of ‘local’ before defining a variable means that it’s scope has become limited. What does this mean? You’ll only be able to access that variable within a certain scope. Not using ‘local’ before defining it would make it a global variable and you can access globals anywhere.

– Example:

do – Create a new block

local x = 2

print( x ) --> Prints '2' because we're accessing the variable within the same block

end – Close this block

print( x ) --> Prints ‘nil’ because the variable’s scope has been exceeded

– Another example:

local a = “Hello World”

do – Create another block

print( a ) --> Prints 'Hello World' because locals' scopes are not limited to sub-blocks

do -- And another new sub-block
	print( a ) --> Once again prints 'Hello World'


:v thanks alot

is there suppost to be a space between the parenthesis? when i added it into the file
[lua]local team = LocalPlayer():Team()[/lua] it didnt work, theres a couple options which I see to it breaking,
first it may because i have BOTH

local ply = LocalPlayer()
local team = LocalPlayer():Team()

or maybe the spaces?

EDIT: i tried without spaces and it still didnt work :frowning:

before I would just get a lua error, now the zz_blackmarket doesnt even work! Unknown command!

Just do

[lua] local ply = LocalPlayer()
local team = ply:Team() [/lua]

I used your method Jamie932, but this just wants to be a comedy of errors.

[lua]attempt to call method ‘Team’ (a nil value)[/lua]

Are you using this clientside?

I would guess not, or LocalPlayer():Team() would be a valid method.

Or he’s doing it when LocalPlayer returns NULL ( before the player exists ).

Yea, I’m doing this clientside

how do i fix that?

So, Salads, that “Triggers “logic_relay” entities named “logic_map_start” when the map loads.”

How Can I use this to my benefit? Would I put a trigger like such in the same client file?
I also looked up “team” on the wiki and found
[lua] local plteam = player.GetByID(1):Team():GetColor() [/lua]
could i use that like such?:
[lua]local plteam = player.GetByID(1):Team() [/lua] just removing color?

Also thanks to the people who have helped me so far.

That would only get the team of the person who’s UniqueID is 1.