I’m making a combat system and want to get the player from the enemy’s character.
I fired the remote event through code like this:
local data = {
["Character"] = character,
["TargetCharacter"] = target -- Note that this is the target's CHARACTER
}
CombatEvent:FireServer(data)
Now when I receive this remote event on the ServerScript, and try to fire the client to the target’s player, I get an error stating “FireClient: player argument must be a Player object”.
I have tried using multiple methods, such as :GetPlayerFromCharacter(), but all gave the same error.
Something to understand about RemoteEvents and RemoteFunctions is that they prepend a Player argument when the server is receiving, and you have to prepend a Player argument yourself when your server code is sending information to individual clients (unless you’re using RemoteEvent::FireAllClients).
For example, here’s some client code that sends the local player’s camera position to the server:
local cameraPos = workspace.CurrentCamera.CFrame.Position
Remote:FireServer(cameraPos)
where Roblox automatically removes the Player argument, since the client doesn’t need it. The client can just use game.Players.LocalPlayer.
On a sidenote, I’ve never found a need to send data to any particular client from the server. If I need to give data to a single client, I always found it made more sense to have the client ask for that information first using a RemoteFunction, where instead of the server having to do RemoteFunction:InvokeClient(player, ...) you can just do return ... from the server side part of the function. Here’s a relevant sequence of posts I wrote if you’re curious
Players:GetPlayerFromCharacter(character) should always give back the player unless the argument given isn’t a character. Considering this isn’t working try printing out target, checking the parent etc. to see if it actually is a character