Which is the better way to get other player character by remote event

If I want to get another player character by the remote event. Which one is better between:

  1. send the player instance
-- LOCAL SCRIPT from player want to send their data
local sendFrom = game.ReplicatedStorage.EventSendFrom
sendFrom:FireServer()
-- SERVER SCRIPT that receives the data then send to another player
local Players = game:GetService("Players")
local sendFrom = game.ReplicatedStorage.EventSendFrom
local sendTo = game.ReplicatedStorage.EventSendTo

sendFrom.OnServerEvent:Connect(function(player)
	for i, otherPlayer in pairs(Players:GetChildren()) do
		if player ~= otherPlayer then
			sendTo:FireClient(otherPlayer, player)
		end
	end
end)
-- LOCAL SCRIPT from player who receive the data
local sendTo = game.ReplicatedStorage.EventSendTo

sendTo.OnClientEvent:Connect(function(fromPlayer)
	-- Get player character that send from
	local fromPlayerCharacter = fromPlayer.Character
end)
  1. send the player name
-- LOCAL SCRIPT from player want to send their data
local sendFrom = game.ReplicatedStorage.EventSendFrom
sendFrom:FireServer()
-- SERVER SCRIPT that receives the data then send to another player
local Players = game:GetService("Players")
local sendFrom = game.ReplicatedStorage.EventSendFrom
local sendTo = game.ReplicatedStorage.EventSendTo

sendFrom.OnServerEvent:Connect(function(player)
	for i, otherPlayer in pairs(Players:GetChildren()) do
		if player ~= otherPlayer then
			sendTo:FireClient(otherPlayer, player.Name)
		end
	end
end)
-- LOCAL SCRIPT from player who receive the data
local sendTo = game.ReplicatedStorage.EventSendTo

sendTo.OnClientEvent:Connect(function(fromPlayerName)
	-- Get player character that send from
	local fromPlayerCharacter = workspace:FindFirstChild(fromPlayerName)
end)

Can anyone explain to me, which way is better? and why? Since this might improve the network performance of the game. Thanks in advance!

Ps.
I’m currently developing a game right now, it’s easy-to-play fighting game and have level-up system. If you guys are interested in being a tester or any contributor, please see my game page: Internet PVP - Roblox . After that join my group and contact me via social media site. I planned to release a very pre-alpha of it at the end of February 2022 for tester only.

why are you sending the player’s character to every other player on the server when you can just do something like this?

sendFrom.OnServerEvent:Connect(function(player)
	for i, otherPlayer in pairs(Players:GetChildren()) do
		if player ~= otherPlayer then
			local fromchar = player.Character
		end
	end
end)

If you really wanted to do it on the client, then sending that player would be the best option. The reason this would be the best option is that it is much easier to do stuff when you have the player itself, such as checking whether or not it has a character

sendTo.OnClientEvent:Connect(function(fromPlayer)
	if fromPlayer.Character then
		local fromPlayerCharacter = fromPlayer.Character
	end
end)

or you could even use anything else like the player’s team, UserId and more.

1 Like

trivial thing like this is not gonna improve your network performance, but if you’re going minimalist u could just send over the player name. if you’re looking for making it more performant u should look into other things

1 Like

Yes, this might look over complicated.

The reason that I want to do this is, I want to play the visual effect on the client. Which the effect needs the CFrame of the character of the player who sent the effect from.

It needs to happen so quickly that is why I want it to send fast. So I try to think of a way to minimalize the data sent through the remote events.

Not sure if it will improve the network performance tho as @nennocyte said it’s so trivial.

Considering you have the player instance on the server-side you could even index its “Character” property to fetch the player’s character model instance and transmit that directly to the client through the RemoteEvent instance instead.