OnClientEvent function prints only if current mode is set to server or if hosting a local server

I’m currently experimenting with remote events and I’m trying to print stuff from within the function that’s bound to the OnClientEvent & OnServerEvent events.

If I’m running in play mode I would need to switch the current mode to the server to be able to receive prints from the OnClientEvent event function. The function is running within a local script so it’s pretty strange to me that I would need to switch the current mode to be the server to be able to read prints or debug within the OnClientEvent function.

Here’s how I set it up.

Server script running from ServerScriptService with RunContext set to Server

local UpdatePart = game.Workspace:WaitForChild("UpdatePart")
UpdatePart.OnServerEvent:Connect(OnUpdatePart)

function OnUpdatePart()
	print("im the server, got called from client")
    UpdatePart:FireAllClients()
end

Local script running from StarterPlayerScripts

local UpdatePart = game.Workspace:WaitForChild("UpdatePart")
UpdatePart.OnClientEvent:Connect(function()
	print("im the client, got called from server")
	UpdatePart:FireServer()
end)

I’ve tried moving the local script to StarterGui and the Workspace but both resulted in it not being printed for the client but works perfectly fine when switching the current mode to the server.

I’ve also tried using BindableEvents but that also resulted in the same issue.

It’s quite surprising this even works because the function doesn’t exist when you connect it. How about you create the function before you connect it?

Unfortunately that didn’t do much of a difference, however I solved the issue. Apparently for some reason calling FireAllClients within a BindToRenderStep event function resulted in the client (atleast in play test mode in studio) to never receive the print message.

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