ply is a nil value

how do i try to fix the error attempt to index local ‘ply’ (a nil value) when ever i try to call my own functions

local function RoundStart ( ply )

	ply:SetTeam( 2 )

i have looked all over google and i cant find some thing to fix this error

Where are you calling the function RoundStart()?
You probably aren’t passing ply to it.

am probably not passing it
i was calling it in a if statement
how would one pass it?

I’m assuming you want to be doing something this this

for k, ply in pairs( player.GetAll() ) do RoundStart( ply ) end

If you want to call it only on certain players, put your if statement inside the for loop.

would it be something like

for k, ply in pairs( player.GetAll() ) 
if (table.Count( player.GetAll ()) == 2 ) then
RoundStart( ply ) 

Nope, if you do it like that you would be calling RoundStart multiple times

if (table.Count(player.GetAll()) == 2 ) then
	for k,ply in pairs(player.GetAll()) do

This code should work, but it will only work if there is a total of 2 players, so I guess you might want to change == to >= if you want to make the round start if there is more than 2 players

oh sorry xD and yeah i forgot the > xP but thanks you

so my problem now it dosent change the team of the player

You made RoundStart as a local function, is the piece of code I gave you in the same file as the RoundStart function? Is RoundStart within another function?

i got it working now dosent worry

He would be getting “attempt to call a nil value” errors if the local function was in another chunk.

Damn, you’re right my bad!

Cool! Good luck then :smiley: