So I recently made a function that communicates between the server and client; the client sends a message to the server, then the server sends a response back to the client. However when I publish online, the text displayed in the debug line on the server end wouldn't display properly. Here is my code:

Local:

local clientToServer= game.ReplicatedStorage:WaitForChild("ClientToServer")

script.Parent.MouseButton1Click:Connect(function()
	local msg1= "[client]: Hello Server!"
	clientToServer:InvokeServer(msg1)
end)

function onClientEvent(msg2)
	print(msg2)
end

clientToServer.OnClientInvoke= onClientEvent

Server:

local clientToServer= Instance.new("RemoteFunction",game.ReplicatedStorage)
clientToServer.Name= "ClientToServer"

function onServerEvent(sender,msg1)
	print(msg1)
	local msg2= "[server]: Hello Client!"
	clientToServer:InvokeClient(sender,msg2)
end
clientToServer.OnServerInvoke= onServerEvent

What I tried to do here was to display it immediately after recieveing the local message, but maybe wondered if it was better to make a GUI to send back to the player, which is onClientEvent

2 comments

0

You should e using local functions, and you're using global. You also should not be using the parent argument of Instance.new, as it is deprecated.

0

But you should be using a RemoteEvent, as you're not returning anything and remote function are required to return.