Remote Event Arguments gets changed

I want to send a string from one client to every other client, so I set up 2 remote events.
1 remote event gets fired on the client sending the string to the server, while the other remote event gets fired from the server to all clients.
When received, I want the string to be put onto a GUI Textlabel, but the string gets turned into the player that sent the string in the first place?
What happens is that, when the first remote event gets fired to server, I attempt to send along the string as well, but it gets turned into the player reference. In this case, I am Ethanlovir, firing the first remote. What the Server receives is a reference to “Ethanlovir”. This, of course, wont work.

Localscript One (Where the first remote gets fired)

player = game.Players.LocalPlayer
char = player.Character
hum = char:WaitForChild("Humanoid")
playername = player.DisplayName

function onDeath()

	local message = {"%s died.", "%s is dead.", "%s flatlined.", "%s gave up.", "Dear diary, I, %s, died.", "%s disappeared", "%s decided to go to brazil.", "%s had enough.", "%s learned what death is.", "%s was taught the concept of death."}
	local msg = message[math.random(1, #message)]
	local deathMessage = string.format(msg, playername);
	print(deathMessage)
	game.ReplicatedStorage.RemoteEvent.DeathMessage:FireServer(deathMessage)
end

hum.Died:Connect(onDeath)

The Print is correct, printing out the string of the Death Message
image
Server Script (Receives first remote, fires second to all clients)

function deathmsg(deathMessage)
	print(deathMessage)
	game.ReplicatedStorage.RemoteEvent.DeathMessage:FireAllClients(deathMessage)
end

remote.DeathMessage.OnServerEvent:Connect(deathmsg)

Remote is a variable for my Remote Event folder in replicated storage. This is what my debug print prints out.
image
Second Localscript (Receives second remote event)

	
	local text = script.Parent.TextLabel
	local border = text.TextStrokeTransparency 
	local transparency = text.TextTransparency
	
	border = 1
	transparency = 1
	
	text.Text = deathMessage.Value
	
	for i = 0, 10 do
		
		border -= 0.1
		transparency -= 0.1
		wait(0.1)
		
	end
	
	border = 0
	transparency = 0
	wait(2)
	
	for i = 0, 10 do

		border += 0.1
		transparency += 0.1
		wait(0.1)

	end
	
	border = 1
	transparency = 1
	wait()
	
end)

Error I get: Value is not a valid member of Player "Players.Ethanlovir" - Client - LocalScript:10

So, what do I do to fix this argument issue?

OnServerEvent passes the player who fired the event as the first argument and then everything else after it. Try doing this instead for your server script.

function deathmsg(player, deathMessage)
	print(deathMessage)
	game.ReplicatedStorage.RemoteEvent.DeathMessage:FireAllClients(deathMessage)
end

remote.DeathMessage.OnServerEvent:Connect(deathmsg)

Also please be aware that text generated by a player that is sent to other players must be filtered. Please take a look at this article for more information on string filtering.

1 Like