Info is not being passed through Remote Events

Hello. I have looked for an answer in the forum and found many posts, but none of them actually solved my issue. I am trying to take the name of an instance and pass it to a server script through a remote event, but it is returning nil instead.

Here’s some of the code:

Client:

local button = script.Parent
local repstorage = game:GetService("ReplicatedStorage")

debounce = true

button.Activated:Connect(function(player)
	if debounce == true then
		debounce = false
		local naim = button.Name -- change button's name
		repstorage.WearArmor:FireServer(player, naim)
		wait(0.1)
		debounce = true
	end
end)

Server:

local storage = game:GetService("ServerStorage")
local repstorage = game:GetService("ReplicatedStorage")

repstorage.WearArmor.OnServerEvent:Connect(function(player, naim)
	
local character = player.Character or player.CharacterAdded:Wait()

	print(character.Name)
	print(naim)

Rather than printing out the name, it is printing out “nil” and the rest of the script does not work because of that. I would like to know how to solve this.

You don’t need to pass the player object when using :FireServer(). This is only necessary when using :FireClient().

Instead of:

repstorage.WearArmor:FireServer(player, naim)

Try:

repstorage.WearArmor:FireServer(naim)
1 Like

That solved the issue. Thank you, although I do not understand why having “player” there was an issue.

1 Like

On the server, the .OnServerEvent event automatically passes the player that sent the signal. Passing the player again on the client with the :FireServer() function will cause another player parameter to show up on the server end:

Lets say you kept the old code:

repstorage.WearArmor:FireServer(player, naim)

The server will receive three parameters instead:

repstorage.WearArmor.OnServerEvent:Connect(function(player, player, naim)
end)

Additionally, I don’t think the button.Activated event passes the player instance.
https://create.roblox.com/docs/reference/engine/classes/GuiButton#Activated

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.