Roblox remote event "Unable to cast value to object?"

In a server script, I am using a remote event to fire a client. I have a variable that is equal to the player’s name I want to fire. I double checked it by printing it.

Here is how I fired it:

for i, v in pairs(players:GetChildren()) do
	if v.Backpack.CharacterChosen.Value == "" then
		local choosingPlayer = v.Name
		autoChoose:FireClient(choosingPlayer)
	end
end

But the remote event never got fired in the client. I looked into the server’s output and it said “Unable to cast value to object.”

How can I get it to recognize the variable as the player?

1 Like

You have to have the actual Player Object as the argument. You are sending the player’s Name, but not the Player Object. You need to send the Player Object first, and then, if you want, send the player’s name.
It should look like this:

for i, v in pairs(players:GetChildren()) do
	if v.Backpack.CharacterChosen.Value == "" then
		local choosingPlayer = v.Name
		autoChoose:FireClient(v, choosingPlayer) -- send player AND THEN player's name
	end
end
3 Likes

You do not really need to get the player’s name. It requires a Player object. You can just do :FireClient(v).

3 Likes