.OnServerEvent() only registers the 'Player' Variable

Hey! I am the creator of the upcoming roblox chat game JustChat, now I have a small problem.

Currently, the chat function is entirely being controlled by one LocalScript which is extremely unsafe, the problem is that the RemoteEvent’s .OnServerEvent() only seems to be register the Player argument, trying to type , after every end of an argument (e.G player, message) just results the second argument to show the sender of that message.

Here is the code I currently use:

script.Parent.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		local FilteredMessage = game.Chat:FilterStringForBroadcast(script.Parent.Text, game.Players.LocalPlayer)
		
		for _,player in pairs(game.Players:GetPlayers()) do
			local ChatMessageTemplateClone = player.PlayerGui.UI.Main.Chat.ChatMessages.UIListLayout.ChatMessageTemplate:Clone()
			local SenderAvatar = game.Players:GetUserThumbnailAsync(game.Players.LocalPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
			ChatMessageTemplateClone.Msg.Text = FilteredMessage
			ChatMessageTemplateClone.Avatar.Image = SenderAvatar
			ChatMessageTemplateClone.Sender.Text = game.Players.LocalPlayer.Name
			ChatMessageTemplateClone.Name = game.Players.LocalPlayer.Name
			ChatMessageTemplateClone.Parent = player.PlayerGui.UI.Main.Chat.ChatMessages
		end
	end
end)

Can anyone tell me why the hell the server only registers the Player Argument?

1 Like

At what point are you firing the RemoteEvent, I can’t seem to find it. Could you provide that, just so it’s easier to see what exactly the issue is?

Off the bat the issue you’re describing sounds like you’re sending the player argument on the client. Once again I could be wrong and I can’t tell without the full code. The player argument is always automatically sent from the client to the server. To futher illustrate my point:

-- example client script
game.ReplicatedStorage.RemoteEvent:FireServer("example string")
-- example server script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, stringSent)
   print(player, stringSent) -- will print "joshoweenn, example string".
-- notice how stringSent on the server is the second parameter, and "player" is automatically the first parameter without having to send the player variable. 
end)


This is basically what I mean by “Only registers Player Variable”

grafik
And it does only print the player who sent it, not the chat message and I have no idea why

You’re still not showing the relevant code to your problem.

Client

Server

Don’t send the LocalPlayer first, just send the chat message. Roblox automatically sends the player first

image

Basically all chat messages with or without whitespaces

Change :FireServer(LPlayer, MessageToSend) to :FireServer(MessageToSend)

I did this, now returning nothing
grafik

You’re storing the value of the TextBox’s Text when the script starts:

image


By default, the TextBox’s text is blank, so it will always be "". If you want to get the newest text information, just store a reference to the Instance, and get the text with .Text when you’re firing the information to the server:

-- Example
local textBox = script.Parent -- Saves a reference to the Instance

--...
RemoteEvent:FireServer(textBox.Text) -- Get the newest information
1 Like

That worked like a charm! Thank you so much!
grafik

2 Likes