RemoteEvent fire not sending over the proper data

I’m trying to make a GUI which lets me edit players leaderstats. Everything works fine, except for a change in the data being transferred through the Remote Event.

LocalScript:

local stat = "Assists"
script.Parent.Add.MouseButton1Click:Connect(function()
	local editedPlayer = script.Parent.Parent.Name
	local typa = "Add"
	editReceiver:FireServer(editedPlayer, stat, typa)
end)

If I was editing my own values. printing here returns: deathrange07, Assists, Add.

Script:

function editReceiver(editedPlayer, stat, typa)
print(editedPlayer)
	print(stat)
	print(typa)
	if editedPlayer ~= nil then
		if stat == "Points" then
			if typa == "Add" then
				...

The prints return the following: deathrange07, deathrange07, Assists.

1 Like

That is because, on the server receiving end, you must ALWAYS add the variable for the player who sent the event, so it should look like this on your normal script

function editReceiver(player, editedPlayer, stat, typa)
print(editedPlayer)
	print(stat)
	print(typa)
	if editedPlayer ~= nil then
		if stat == "Points" then
			if typa == "Add" then
				...
3 Likes

You can also use the variable of the player to get info from the sender, for example:

print(player.Name)

or if you were making game health-related:

print(player.Character.Humanoid.Health = player.Character.Humanoid.Health - 10)

and I see you are using a variable called editedPlayer, you might not need that variable if you use the player variable.

1 Like