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

RemoteEvent paramaters not being sent?

I have a LocalScript in a tool that will send a RemoteEvent to the server called 'messageSend', once a player chats in the chat. The RemoteEvent's paramaters should contain the player's name, and the player's message. However, once the server recieves the RemoteEvent, it appears that only the player's name has been sent, as when I print both, the player's username is printed twice, instead of once, followed by the player's message. Could you help please?

LocalScript:

player = game:GetService("Players").LocalPlayer

player.Chatted:Connect(function(msg)
	msg = tostring(msg)
	game:GetService("ReplicatedStorage").Events.messageSend:FireServer(player, msg)
end)

ServerScript:

local function eventFired(player, msg)
	print(player.Name)
	print(msg)
end

game:GetService("ReplicatedStorage").Events.messageSend.OnServerEvent:Connect(eventFired)

2 comments

0

You don't need to pass player as an argument with FireServer, only FireClient.

0

Yes I do, as I am wanting the fire all clients in the serverscript after I have the paramaters figured out.

1 answer

✓ Accepted answer

You only need to fire "msg" to the server. Player is always the first parameter in the server, what you sent to the server was (player, player, msg). Roblox automatically sends the player, so all you needed to do is fire (msg) to the server. Then msg is always your 2nd parameter after player.

Client:

player = game:GetService("Players").LocalPlayer

player.Chatted:Connect(function(msg)
    msg = tostring(msg)
    game:GetService("ReplicatedStorage").Events.messageSend:FireServer(msg) --1 parameter
end)

Server:

local function eventFired(player, msg)
    print(player.Name)
    print(msg)
end

game:GetService("ReplicatedStorage").Events.messageSend.OnServerEvent:Connect(eventFired)

1 comment

0

Thank you, it worked. Answer accepted.

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