Solved: It seems :InvokeClient()'s first argument is the real player object. I found that in my local script code it was using plr as the real message and the msg argument was not something used at all. I just overlooked this problem by not opening up wiki :P

I have a small piece of code to test out remotefunctions between a Client script and Server script. I want the server to send a certain message to the player that is being indexed in a for loop:

Like so: RemoteFunction:InvokeClient(playersInServer[i].Name, tostring("Starting a new game."

The problem is that in my local script, it is printing NIL in the console when I print the msg being requested.

Here is the Server Script with the same thing but including my for loop:

--Get players that are in some table
for i = 1, #playersInServer do
	print("Turn: "..playersInServer[i]) --me debugging aaaa

	RemoteFunction:InvokeClient(playersInServer[i].Name, tostring("Starting a new game."))
end

Here is my Client/local Script that starts the function after the server invokes the client:

function RemoteFunction.OnClientInvoke(plr, msg)
	print("Debug1 "..tostring(msg)) --this is what shows me nil instead of that message

	if plr == player.Name then
	playerGui = game:GetService("Players"):FindFirstChild(plr):FindFirstChild("PlayerGui")	

	--After this the function creates a GUI that the player should see with the message given.	
	end
	wait(3)

end

I'm probably missing something in here or something I don't get. Thanks!

2 comments

0

My question is why are you using tostring() on a string?

0

Forgot to delete that. Copied and pasted something from earlier.