RemoteEvent fires only after a connection

Hello!!
I have a remote event that fires every time the mouse clicks. Tho I’ve noticed, that when I add print to the connect function, it prints everything that has been passed in fireserver before.
(Meaning the :FireServer() waited until a connection was made)


:red_square: Fired on the client, real-time.
:blue_square: Fired on the server, all at once when a function was connected to OnServerEvent.

I could solve this by adding a simple :Connect(function()end) at the start of my script, but im unsure if that’s okay or that the script would be slower etc…

Are there any other ways to solve this, or should i stick to that?
Thanks in advance!! :D

1 Like

I have recreated your situation (at least I think I did so) and the problem is that you have a connection inside a connection (probably), since you are saying that :FireServer() only works after you have already connected to the client and it prints all at once on the server.

Just imagine that a connection is a plug. Each time you connect, a plug gets connected too. Now in your situation where you have a connection inside a connection, maybe like this:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() -- First Connection
	print("Client")
	UserInputService.InputBegan:Connect(function(Input) -- Second Connection inside first one
		if Input.KeyCode == Enum.KeyCode.E then
			game.ReplicatedStorage.RemoteEvent:FireServer()
		end
	end)
end)

(this is my recreation which has the same thing happening. I made it simple and fast)

it would look like this as plugs:

Now after you fire your Remote-Event to connect to the client, the plug gets connected. Like this:


And only at this moment your second connection will be able to connect. That’s the reason why :FireServer() is waiting until you made the first connection. I mean, connecting the second plug wouldn’t make much sense if the first one isn’t connected, right? Nothing would happen.

The only way to fix this is by trying to put the connection with the :FireServer() command outside your first connection. Then you would have 2 individual plugs where the second one isn’t depending on the first one.

Now let’s talk about the problem of everything being fired at once on the server.

Lets get back to this picture here where you have fired your Remote-Event to the client already:

Each time when you fire your Remote-Event to the client for the first connection, there’s a new connection.

In this case you did it 3 times:


(Yeah, electricity probably doesn’t work that way, but we only need to understand what I want to explain here.)

Now when you fire your Remote-Event for the second connection, this happens:

in my case:
image

You can only get rid of all of this by coding the second connection somewhere else outside your first connection.

Don’t do this:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() -- First Connection
	UserInputService.InputBegan:Connect(function(Input) -- Second Connection inside first one
		game.ReplicatedStorage.RemoteEvent:FireServer()
	end)
end)
2 Likes

it’s more like a waterpipe. if the remote event is not connected yet, then data are stuck in the pipe, until the first connection happen, then all the data will be flushed out.

3 Likes

Wow, love the explanation!! Tysmmm :DDD

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.