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
[code]
local function RoundStart ( ply )
hook.Call("playerslives")
ply:SetTeam( 2 )
ply:Spawn()
end
[/code]
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.
[QUOTE=Mrkrabz;47793000]Where are you calling the function RoundStart()?
You probably aren't passing ply to it.[/QUOTE]
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
[lua]
for k, ply in pairs( player.GetAll() ) do RoundStart( ply ) end
[/lua]
If you want to call it only on certain players, put your if statement inside the for loop.
[QUOTE=James xX;47793262]I'm assuming you want to be doing something this this
[lua]
for k, ply in pairs( player.GetAll() ) do RoundStart( ply ) end
[/lua]
If you want to call it only on certain players, put your if statement inside the for loop.[/QUOTE]
would it be something like
[code]
for k, ply in pairs( player.GetAll() )
do
if (table.Count( player.GetAll ()) == 2 ) then
RoundStart( ply )
end
end
[/code]
[QUOTE=Jenssons;47793340]would it be something like
[code]
for k, ply in pairs( player.GetAll() )
do
if (table.Count( player.GetAll ()) == 2 ) then
RoundStart( ply )
end
end
[/code][/QUOTE]
Nope, if you do it like that you would be calling RoundStart multiple times
[code]
if (table.Count(player.GetAll()) == 2 ) then
for k,ply in pairs(player.GetAll()) do
RoundStart(ply)
end
end
[/code]
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
[QUOTE=raphy963;47793404]Nope, if you do it like that you would be calling RoundStart multiple times
[code]
if (table.Count(player.GetAll()) == 2 ) then
for k,ply in pairs(player.GetAll()) do
RoundStart(ply)
end
end
[/code]
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[/QUOTE]
oh sorry xD and yeah i forgot the > xP but thanks you
[QUOTE=raphy963;47793404]Nope, if you do it like that you would be calling RoundStart multiple times
[code]
if (table.Count(player.GetAll()) == 2 ) then
for k,ply in pairs(player.GetAll()) do
RoundStart(ply)
end
end
[/code]
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[/QUOTE]
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?
[QUOTE=raphy963;47796478]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?[/QUOTE]
i got it working now dosent worry
[QUOTE=raphy963;47796478]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?[/QUOTE]
He would be getting "attempt to call a nil value" errors if the local function was in another chunk.
[QUOTE=James xX;47796491]He would be getting "attempt to call a nil value" errors if the local function was in another chunk.[/QUOTE]
Damn, you're right my bad!
[QUOTE=Jenssons;47796484]i got it working now dosent worry[/QUOTE]
Cool! Good luck then :D
Sorry, you need to Log In to post a reply to this thread.