Networking not working

Im having a issue with networking for some reason.
Server side code

			net.Start( "EndRoundSong" )
				net.WriteString( )
				net.WriteString( result )

This is the client side code

	net.Receive("EndRoundSong", function()
		local song = net.ReadString() or ""
		local winners = net.ReadString() or ""
		LocalPlayer():ChatPrint( "Song: " )
		sound.PlayFile( song, "mono", function( station )
			if IsValid( station ) then
				EndRoundMusic.Station = station

Currently the issue is the client isn’t receiving anything not even running the function in net.Receive() i debugged what I’m sending and every value is set before it is sent.

First of all.
Where are you calling util.AddNetworkString(“EndRoundSong”)?
You should call it outside of every function, so it gets called on files load.
Do you have any errors on the servers console? Or on the client?

No errors what so ever, and i am i just posted the network stuff, util.AddNetworkString(“EndRoundSong”) is at the top of the code right below if SERVER then. This was just working then all the sudden just broke i have no idea why though

Put a print before the net.Start and see if it prints in the console. You may be not calling the net.Start on the server.
That, or maybe the clientside code isnt running, 1 of those 2.

Server side code
Client side code

[editline]12th September 2016[/editline]

i put a print in the net.Send() and its printing so its something to do with the client, also both files are being added using AddCSLuaFile in shared.lua

1 error:
When checking if the result of a round on the TTTEndRound hook, you are checking for a string when its an enum, so on the ifs remove the: “” that are in WIN_TRAITOR, WIN_INNOCENT and WIN_TIMELIMIT, going from:
(lines 49, 55)

if result == "WIN_TRAITOR" then = EndRoundMusic.TraitorSongs[math.random( 1, #EndRoundMusic.TraitorSongs )] or ""
      elseif result == "WIN_INNOCENT" then = EndRoundMusic.InnocentSongs[math.random( 1, #EndRoundMusic.InnocentSongs )] or ""
      elseif result == "WIN_TIMELIMIT" then = EndRoundMusic.TimeLimitSongs[math.random( 1, #EndRoundMusic.TimeLimitSongs )] or ""

if result == WIN_TRAITOR then = EndRoundMusic.TraitorSongs[math.random( 1, #EndRoundMusic.TraitorSongs )] or ""
      elseif result == WIN_INNOCENT then = EndRoundMusic.InnocentSongs[math.random( 1, #EndRoundMusic.InnocentSongs )] or ""
      elseif result == WIN_TIMELIMIT then = EndRoundMusic.TimeLimitSongs[math.random( 1, #EndRoundMusic.TimeLimitSongs )] or ""

Now instead put a print in the clients net.Receive printing out all the info that the client receives.

If you notice there is LocalPlayer():ChatPrint( "Song: "…song)

also “WIN_INNOCENT” and the others have been working this way but I’ll change them anyways

Is shared.lua being AddCSLuaFile’d and included on the client?


Well it shouldn’t work:

Its an enum (aka: number assigned to a global variable), its never an string, and therefore if you put it as a string it shouldn’t work.

Like i said it was recently just working and if it that wasn’t already done none of them would load. I’m using gcompute and I did

net.Receive("EndRoundSong", function()

and it prints test so its something with the file but i don’t know why this just started to happen even when i didn’t touch the networking part.

Are you including it clientside?

[editline]12th September 2016[/editline]

As you have just stated that means that its something with loading the clientside file.
Check in the console for include errors, or maybe its just that the files that are supposed to include the files on the client aren’t even loading on the client.

wow pretty sure i see my problem here

[editline]12th September 2016[/editline]

Well i had a stupid error with the sound.PlayFile() section where I’m checking if its valid i forgot the end

[editline]12th September 2016[/editline]

Thanks for you guys help, and geferon I switched from using strings to the enum