Serverside generated random

I want to edit prophunters gamemode.
What I want: Random music that generated by server(same to all clients) and playing at the end of round.
What I do:
in file sv_rounds.lua


    include("sh_endroundboard.lua")
    ...
    function GM:EndRound(reason)
       generate_and_send()
    ....
    end
     

file sh_endroundboard.lua


    if SERVER  then
    util.AddNetworkString("random_number")
     
       -- serverside function to send a random number to the client - call however you want
       function generate_and_send()
         -- edit for your desired range
         end_music = math.random(0, 8)
     
         for _, ply in pairs(player.GetAll()) do
            net.Start("random_number")
            -- you shouldn't need more than 32 bits
            net.WriteUInt(end_music, 32)
            net.Send(ply)
         end
       end
    end
     

in cl_endrounboard


    include("sh_endroundboard.lua")
    ....
    SetVisible(true)
    local end_music
     
       net.Receive("random_number", function()
       end_music = net.ReadUInt(32)
     
       end)
    if end_music == 0 then
    ....
     

In console no errors, but end_music == nil. Help me please

You are checking for end_music == 0 outside of the net.Receive function, when that code runs the client hasn’t received the net message yet thus end_music is still nil. Move the code that checks for end_music == x inside the net.Receive() function like this:

[LUA]
include(“sh_endroundboard.lua”)

SetVisible(true)

   net.Receive("random_number", function()
         local end_music = net.ReadUInt(32)
         if end_music == 0 then
                 playMusic(0)
         elseif end_music == 1 then
                 playMusic(1)
        ....
         end
   end)


[/LUA]

thank you