Gmod send message to client

Hello guys!

I am currently hosting a TTT Server in garrysmod and want to play a random song after each round! (Each song is listed in an Array with the numbers 0 to 11).
Right now everything works as following: After each round a random number is being generated by the client to select the song! My problem is, that each client gets another song picked, because the file is client based! I want the server to random generate a number and send it to the client, so everyone can listen to the same song. You may think why i want to do this: It’s just that the songs are very catchy and it’s very weird if someone is singing another song than you are listening to :smiley:

I hope someone can help me!

Thank you in advance,
Simon aka. EPEffects


-- Just put this somewhere at the top of a file on the server's side
util.AddNetworkString("SendSong")

-- Serverside Code, when the round ends
local songID = math.random(11)

net.Start("SendSong")
net.WriteInt(songID, 32)
net.Broadcast()

-- Clientside code, not inside any function just on its own
net.Receive("SendSong", function()
    local song = net.ReadInt(32)
    -- play the song from the table of songs
end)

Thank you! It works for me!