Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does OnClientEvent work without the use of remote event(s)?

Basically, whenever I put onClientEvent with my remote event it doesn't work. But when I don't use it it works.

Client side:

local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
    print "It works" 
end)
  RemoteEvent:FireServer()

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Gets the REP (Replicated Storage)
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent.OnServerEvent:Connect(function(player)
	if player.Name == "JesseSong" then
		print "idk"
	end
	end)
	RemoteEvent:FireClient(game.Players:WaitForChild "JesseSong")

EDIT: OnClientEvent is used to communicate to the server and client multiplte times vice - versa, if you only wante it to do it from the server to client. Then you don't need an on client event - :FireClient.

6 comments

0

Can I see your Server script?

0

First question is why do you fire to server right after you receive event from server (you can replace it with remote function). Could you provide server-side code and erros if there are.

0

I edited

0

It only works when I remove OnClientEvent function

0

Also, there isn't any error

0

You never fired the event so it won't work.

1 answer

✓ Accepted answer

You created "infinite loop"

You never fire to server and you never fire to the client. In the client-side code FireServer() will get fired when you fire remote from the server to client because it's inside of OnClientEvent and you never fire to the client. Could you tell me what you are trying to do? If you wanted to fire from client to server this is how it should look like:

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
   
RemoteEvent:FireServer()

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player)
    print("received event from "..player.Name) 
end)

6 comments

0

When I use :FireClient it still doesn't work

0

Could you send the code that works?

0

I tested this and it works, what scripts are you using and where are they placed?

0

Is there a need of OnClientEvent?

0

On ClientEvent is used when you are receiving remotes from server to client, if you want client to server then it's not needed.

0

Essentially, you merged client-server and server-client communication together which won't work

This discussion is preserved as it was. New answers, comments, and votes are closed.