Sent Value is nil when it is not supposed to be

I am using 2 remote events to send the value of a string value to the server, then back to all clients. The script that receives the remote event that goes back to the clients checks if the value of the string value is the same as another string/value. it determines wether that part of the code is fit to go on, but apparently the value I send over the events is nil. in the same way, with the same scripting, I have sent values just like that without them turning nil, so I am very confused.
This is the part of the code that sends the remote event

game.ReplicatedStorage.JoinPlayerToClient.OnClientEvent:Connect(function(Player, Owner) 
	if Player.Name == game.Players.LocalPlayer.Name then
		script.Parent.Parent.Players.HostPlayer.Player.Value = Owner
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	local Owner = script.Parent.Parent.Players.HostPlayer.Player.Value
	print(script.Parent.Parent.Players.HostPlayer.Player.Value)
	game.ReplicatedStorage.RemovePlayerToServer:FireServer(Owner)
end)

This is the code that passes it back to the client

game.ReplicatedStorage.RemovePlayerToServer.OnServerEvent:Connect(function(player: Player, Owner)
	game.ReplicatedStorage.RemovePlayerToClient:FireClient(player, Owner)
end)

This is the code that receives the event passing to the client

game.ReplicatedStorage.RemovePlayerToClient.OnClientEvent:Connect(function(player, Owner)
	print(script.Parent.HostPlayer.Player.Value)
	print(Owner)
	if Owner == script.Parent.HostPlayer.Player.Value then
		if script.Parent:FindFirstChild("GeustPlayer1") then
			GeustPlayer1 = script.Parent:FindFirstChild("GeustPlayer1")
		end
		if script.Parent:FindFirstChild("GeustPlayer2") then
			GeustPlayer2 = script.Parent:FindFirstChild("GeustPlayer2")
		end
		if script.Parent:FindFirstChild("GeustPlayer3") then
			GeustPlayer3 = script.Parent:FindFirstChild("GeustPlayer3")
		end
		if GeustPlayer1.Player.Value == player.Name then
			GeustPlayer1.TextLabel.Text = GeustPlayer2.TextLabel.Text
			GeustPlayer1.ImageLabel.Image = GeustPlayer2.ImageLabel.Image
			GeustPlayer1.Player.Value = GeustPlayer2.Player.Value
			GeustPlayer2.TextLabel.Text = GeustPlayer3.TextLabel.Text
			GeustPlayer2.ImageLabel.Image = GeustPlayer3.ImageLabel.Image
			GeustPlayer2.Player.Value = GeustPlayer3.Player.Value
			GeustPlayer3:Destroy()
		elseif GeustPlayer2.Player.Value == player.Name then
			GeustPlayer2.TextLabel.Text = GeustPlayer3.TextLabel.Text
			GeustPlayer2.ImageLabel.Image = GeustPlayer3.ImageLabel.Image
			GeustPlayer2.Player.Value = GeustPlayer3.Player.Value
			GeustPlayer3:Destroy()
		elseif GeustPlayer3.Player.Value == player.Name then
			GeustPlayer3:Destroy()
		end
		if player.Name == game.Players.LocalPlayer.Name then
			script.Parent.Parent.Visible = false
			script.Parent.Parent.Parent.LobbyListUi.Visible = true
		end
	end
end)

Just to specify, some unnecessary code has been removed, only the essentials are present, incase you see something that doesn’t make sense.

I think the issue here might be that lua passes these arguments by reference. For instance, if you send a part, it won’t create a new one and send that, it will send the original part.

In this case, Value is under the player. I can’t really tell what value is or anything (If this doesn’t help, I’d love to see the explorer of a Player instance in-game), but it seems that you’re passing the reference of the instance, instead of a string itself.

I’d recommend printing and checking the type of what you’re sending. You might even be able to fix this with something as simple as a tostring() when you send it.

Good luck, let me know if this helps or doesn’t.

Firstly, You can’t retrieve player like this as the first argument is just the player u want to send it to so just delete player and write it like this
game.ReplicatedStorage.RemovePlayerToClient.OnClientEvent:Connect(function(Owner)

Secondly use FireAllClients if u want to send to all the clients, using FireClient(player) will cause the event to go to that specific player only, then retrieving the player object from the client with
game.ReplicatedStorage.RemovePlayerToClient.OnClientEvent:Connect(function(player)
wouldnt work, so do this instead.

game.ReplicatedStorage.RemovePlayerToClient:FireAllClients(Owner)

I managed to find a solution. I stopped working on that game for a while, so this reply is super late, sorry.

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