I don't get this. Take a look:
I have a localscript named "Test" here it is:
local modules = game.Workspace["Module(s)"]; local chathandler = require(modules.ChatHandler); local msg = ("I love icecream."); chathandler.test(game.Players.LocalPlayer,msg);
I have a modulescript, here's how it looks in relation to that code:
function chathandler.test(player,msg) chatAdd:FireServer(player,msg); end
Now here's the RemoteEvent which should print the msg correctly:
chatAdd.OnServerEvent:connect(function(player,msg) print(msg); end)
What's going on? Why does it print the Player's name but not the msg itself? Is it not passed correctly?
EDIT (Update, just uses msg this time): Still doesn't work.
New localscript:
local modules = game.Workspace["Module(s)"]; local chathandler = require(modules.ChatHandler); local msg = ("I love icecream."); chathandler.test(msg);
Modulescript:
function chathandler.test(msg) chatAdd:FireServer(msg); end
RemoteEvent:
chatAdd.OnServerEvent:connect(function(msg) print(msg); end)
This has to do with something a little funky about RemoteEvents.
When you cal :FireServer()
on a RemoteEvent from a client, it automatically passes the player that called it as the first argument.
So that means this:
remoteEvent:FireServer()
would need this on the server to work properly:
remoteEvent.onServerEvent:connect(function(plr) --print(plr) end)
You can pass other arguments through the RemoteEvent, but the player that called the server will always be the first argument received.
I think it is because of your local script.
When using remote events in the local script, the first argument is automatically defined as player, so the first thing you send to a remote event in the local script will be looked as the second argument, so it thinks the msg is the player.