Make methods to happen for every player

I have found this: but im new with lua

I want to make something to print for every players, for example player:PrintMessage to happen to every player online.

for k,v in pairs( player.GetAll() ) do

v:PrintMessage( HUD_PRINTTALK, “hello” )


Can you explain the for loop for me? I have never understood the k,v in pairs stuff

for key, value in pairs( player.GetAll() )

print( key, value:Nick() )


output: 1 Invule. Where the KEY is 1 and the VALUE is Invule

edit: You can also read about it here.

k it’s the player index number, the first player to join normally will be 1, and the last player will be like 4 or 5 (In the case there are 4 or 5 players) and v it’s the player itself

it’s for key, values, key it’s the index of the array:
local tbl = {apple=“ok”,banana=“rock”}
local ntbl = {"ok,“rock”}

for k,v in pairs(tbl) do
MsgN(k…" “…v)
for k,v in pairs(ntbl) do
MsgN(k…” "…v)

//Will print:
//apple ok
//banana rock
//1 ok
//2 rock

Thanks, you explained it very good :slight_smile: