How would I do this?

I am getting a error:
[lua]
Timer Error: [gamemodes\secretspy\gamemode arget_select.lua:14] table index is nil
[/lua]
and I think its to do with that if function PickedPlayer more then once(if the conditions arnt met and it runs twice) the variable pickedPly is set as a nil value, but the question im asking is, how would I get PlayerPicked to repeat and return the value I want?
[lua]
function GM:StartSelection()
info = {}
info[“target”] = {}
info[“selected”] = {}

for _,v in pairs(player.GetAll()) do
	info["selected"][v] = 0
end

for _,ply in pairs(player.GetAll()) do
	print(ply)
	local pickedPly = PickedPlayer(ply)
	info["target"][ply] = pickedPly
	info["selected"][pickedPly] = 1
end

end

function PickedPlayer(ply)
local randPly = table.Random(player.GetAll())
print(randPly)
if(info[“selected”][randPly] == 1) or (randPly == ply) then
PickedPlayer(ply)
else
return randPly
end
end

[/lua]

Try moving the PickedPlayer function above the Hook.

didnt work

-snip-

Try that
[lua]
info = {}
info[“target”] = {}
info[“selected”] = {}

function PickedPlayer(ply)
local randPly = table.Random(player.GetAll())
print(randPly)
if(info[“selected”][randPly] == 1) or (randPly == ply) then
PickedPlayer(ply)
else
return randPly
end
end

function GM:StartSelection()
for _,v in pairs(player.GetAll()) do
info[“selected”][v] = 0
end

for _,ply in pairs(player.GetAll()) do
    print(ply,PickedPlayer(ply), info["target"][ply],info["selected"][PickedPlayer(ply)])
    //local pickedPly = PickedPlayer(ply) // Only sets the target once
    info["target"][ply] = PickedPlayer(ply) // Sets it multiple of times
    info["selected"][PickedPlayer(ply)] = 1
end

end
[/lua]

Give results of the error and post what it’s prints

[Lua]
Player [7][Bot06]Player [8][Bot07]
Player [1][SweeneyPaul] Player [7][Bot06] nil
0Player [1][SweeneyPaul]
Player [1][SweeneyPaul]
Player [5][Bot04]
Player [2][Bot01]
Player [3][Bot02]
Player [5][Bot04]Player [2][Bot01]
Player [3][Bot02] nil 0
Player [7][Bot06]
Player [4][Bot03]
Player [8][Bot07]
Player [1][SweeneyPaul]
Player [3][Bot02] Player [8][Bot07] nil0
Player [7][Bot06]
Player [5][Bot04]
Player [3][Bot02]
Player [6][Bot05]
Player [4][Bot03]0
Player [3][Bot02] nilPlayer [6][Bot05]
Player [7][Bot06]
Player [6][Bot05]
Player [5][Bot04]Player [6][Bot05]
Player [6][Bot05] nil 0
Player [4][Bot03]
Player [2][Bot01]
Player [5][Bot04]Player [1][SweeneyPaul]

Player [3][Bot02]
Player [7][Bot06]
Player [1][SweeneyPaul]
Player [4][Bot03]
Player [2][Bot01]
Player [6][Bot05]
Player [3][Bot02]
Player [1][SweeneyPaul]
Player [6][Bot05] nil nil nil
Player [2][Bot01]
Player [1][SweeneyPaul]
Player [4][Bot03]Player [2][Bot01]

Player [4][Bot03]
Player [6][Bot05]
Player [1][SweeneyPaul]
Timer Error: [gamemodes\secretspy\gamemode arget_select.lua:56] table index is nil

[/lua]

And what was the console error before?

If you sent me the gamemode I’d be able to fix it asap

PM me with the zipped up gamemode

Do another test with out print(randPly) in there it’s kinda hard to see the errors

Guessing

Player [6][Bot05] nil 0

info[“selected”][PickedPlayer(ply)] = 1

No where

Player [6][Bot05] nil nil nil

On line 22, change
[lua]
PickedPlayer(ply)
[/lua]
to
[lua]
return PickedPlayer(ply)
[/lua]

Thanks ralle105, It works perfectly :D, I thought it might be something quite simple and thanks RetTurtl3, I appreciate you help

I could’ve just tested it in game and return’d what ralle said(Which was my first idea) :stuck_out_tongue: