net.Receive not getting a broadcast?

Hello, thank you for spending some time to help me.
I have encountered a technical difficultity in broadcasting and receiving strings.
At first my technique worked but now it only works sometimes when I open the script. I don’t know why but each time I edit the script it works but afterwards it stops working.

This is the part that I am talking about:


util.AddNetworkString("Count")
	net.Start( "Count" )
	net.WriteString( "30" )
	net.Broadcast()


FULL SERVERSIDE SCRIPT


util.AddNetworkString("Count")
	net.Start( "Count" )
	net.WriteString( "30" )
	net.Broadcast()

local class = {}
-- Variables
class.Break	= 3	-- break time in secondes
class.Time	= 5	-- class time in secondes

function class.Broadcast(Text)
	for k, v in pairs(player.GetAll()) do
		v:ChatPrint(Text)
	end
end

----------------------------------------------------------------------------------------------
---- 1st Class
function class.Begin()
	-- Your code
	-- (Anything that may need to happen when the class begins)

	class.Broadcast("Class started! It ends in " .. class.Time .. " seconds!")
	timer.Simple(class.Time, class.End)
end

function class.End()
	-- Your code
	-- (Anything that may need to happen when the class ends)
	
	class.Broadcast("Class over!")
	timer.Simple(5, class.Begin2)
end
----------------------------------------------------------------------------------------------
---- 300 Secondes break
function class.Begin2()
	--- Make timer count 300 secondes
	class.Broadcast("Break Time, you've got 300 Secondes!")
	timer.Simple(300, class.End2)
end

function class.End2()
	-- Your code
	-- (Anything that may need to happen when the class ends)
	
	class.Broadcast("Break Time over! Next class in " .. class.Break .. " seconds!")
	timer.Simple(class.Break, class.Begin3)
end

A BUNCH OF CODE (SAME LINE...)

class.Begin()

This is the Clientside script:


print("Countdown Lua Openned")
x = 50
y = 150
d = 10
d2 = d*0.5
h = 160
w = 370

---------------------------------------------------
----------------- Setting the Font ----------------
surface.CreateFont( "CountFont", {
	font = "Arial",
	extended = false,						
	size = 30,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

net.Receive("Count", function ()
	local CountSecondes = net.ReadString()
	print(" ")
	print("-=-=- Received COUNT it's "..CountSecondes.." Secondes -=-=-")
	print(" ")
end)

What happens on my side is: Sometimes I get the 3 print messages and sometimes I don’t get them.
Could you help me to find out why it doesn’t work properly?
Yesterday I tried to fix it for over than an hour, I tried replacing lines of code…
Please help me!

Jacob? Is it a scriptfodder job again? :boxhide:

???
I am doing a script on my own for my school rp server. I tried at least 20 times to fix it and I couldn’t manage to find the mistake.
I am asking if anyone can help me find the mistake, how does that asking for someone to do the job for me? I read every rule to comply with them and I still get people trying to close my thread?

You are calling broadcast without calling net.start.

But itsn’t net.start on the 2nd line?
Or is it not in the good position?

That’s a whole different issue. Your calling a net message before any client could possibly be connected.

In any case, you always been to call net.start before any net message. Always.

First of all thank you for your help and second of all:
Should I put a timer on it like so:


util.AddNetworkString("Count")

timer.Simple( 5, function()

net.Start( "Count" )
	net.WriteString( "30" )
	net.Broadcast()
end )

If you want it to be ran when a player is connected, why not use a

GM:PlayerInitialSpawn hook?

that’s actually an awesome idea but I want it to start on a specific time

Clients connect at different times, having a 5 second timer to broadcast the message will only send it to people that are connected at that 5 second mark. If you could explain what you’re attempting to do it’d be helpful

I am basically doing a countdown timer.
So when a countdown is called it will ask for all connected clients to start a countdown.
But the net.Start and broadcast as shown wouldn’t work on the scrit I’ve made.
I am trying to find out the problem to it.
Sometimes the client receives the broadcast sometimes it doesn’t (I am testing it on my singleplayer server, and running the client script first)

https://scriptfodder.com/jobs/view/15831

You may want to re-read the Net Library wiki page. You want your net.Start(“whatever”) stuff to be inside a function or hook, not just randomly floating at the top of a file, otherwise it’s going to run once when that file is loaded by the server, which is not the same as a client connecting. Your net.Recieve is fine

Are you basically trying to make a classroom timer for SchoolRP? Players can join and leave at anytime - the way I would do it is have the timer handled serverside, i.e have a serverside variable called myTimer which is set to a constantly changing value. Then when someone joins, on PlayerInitialSpawn, send myTimer to them

Yes indeed I am the Co-Founder of that server and it has been a
couple pf days I am developping this script that my Founder asked me but I am not good with lua.
He received some steam messages with people trying to sell him stolen server files, altought he doesnt understand I tell hom that they are only clientside.
Ao I am trying to test do the script meanwhile he is going to get spammed with people wanting either to be selling him stolen files either sell him a similar script. By the time he will find someone I would probably already be finished. (He is very inpatient)

If you have enough lua knowledge you could apply. So it would spare me lots of time and the job would be done. I still intend to continue the script I learnt lots of new things from it.

[editline]6th March 2017[/editline]

Thank you very much for your reply.

Actually what we were trying to do is have it so the server runs:
Start First Class 500 Secondes
Start Break 300 Secondes
Start Second Class 500 Secondes
Start Third Class 500 Secondes

But we wanted to make it so you could see a live countdown of how much time is left.
So it would send a net.String to the client with how many secondes should be the timer
Then the client would receive the command and make a hud indicating the time left.
The problem was that i tried to test but the client sometimes didnt even receive the net.Broadcast.
I will keep ot count what you’ve said and try to see if I can fix it and make it so when a class starts te countdown is started for all connected clients.

And again thank you for your help