FireClient: player argument must be a Player object

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So when you kill an npc you get Souls(Coins) and i want to also make a ui pop up that says +(num) Souls im trying to do that by firing an event and then show the ui on the other local script where i receive the event.

  2. What is the issue? Include screenshots / videos if possible!
    I get this error FireClient: player argument must be a Player object

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked everywhere cant find a solution
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

1st Script:
local Humanoid = script.Parent.Humanoid

function kill() 
   local Tag = Humanoid:FindFirstChild("creator") 
   if Tag ~= nil then 
      if Tag.Value ~= nil then 
          local Leaderstats = Tag.Value:findFirstChild("leaderstats") 
          if Leaderstats ~= nil then 
           Leaderstats.Souls.Value = Leaderstats.Souls.Value + 250 --Change Money to the stat that is increased.
           local Player = game.Players:GetPlayerFromCharacter(Tag.Parent) 
game.ReplicatedStorage.SoulsEvent:FireClient(Player)
           wait(0.1) 
           script:remove() 
         end 
      end 
   end 
end 

Humanoid.Died:connect(kill) 
2nd Local Script:
local player = game.Players.LocalPlayer
game.ReplicatedStorage.SoulsEvent.OnClientEvent:Connect(function()
	player.PlayerGui.ScreenGUI.Soul.Visible = true
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Your Player variable is not the player.

On this line: local Tag = Humanoid:FindFirstChild("creator") you define Tag as a child of the Humanoid, however when you call GetPlayerFromCharacter you only have 1 .Parent as the argument, which points to the humanoid. GetPlayerFromCharacter takes the Character not the Humanoid as the argument.

All you need to do is add .Parent to the end like so:
local Player = game.Players:GetPlayerFromCharacter(Tag.Parent.Parent)

Still gives me the error: FireClient: player argument must be a Player object

Can you check what the variable Tag is?

i printed it and it says creator

Check that you are indexing the players character. What is Tag.Parent.Parent?

So tag = creator , Player = nil , Tag.Parent = Humanoid , Tag.Parent.Parent = NPC no players character here.How should i tag players character ? Any ideas

Are you trying to get the Player from a NPC Character? That’s not possible as the NPC doesn’t have a player object.

When you kill the npc you get Souls(coins) added to your leaderboards so it somehow tags the player and now i want to also send a Event for that same player and show him a UI to tell him that he got Souls

Ah, I assumed it was from the player.

:GetPlayerFromCharacter only works with the players character.

I would say it is easiest to do something along the lines of:
game.Players:FindFirstChild(PlayerName)

So instead of local Player = game.Players:GetPlayerFromCharacter(Tag.Parent.Parent) i should do local Player = game.Players:FindFirstChild(PlayerName) ? if so what should i do with PlayerName because its not defined anywhere

   local Humanoid = script.Parent.Humanoid

    function kill() 
       local Tag = Humanoid:FindFirstChild("creator") 
     if Tag ~= nil then 
      if Tag.Value ~= nil then 
          local Leaderstats = Tag.Value:findFirstChild("leaderstats") 
          if Leaderstats ~= nil then 
           Leaderstats.Souls.Value = Leaderstats.Souls.Value + 250
           local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent) 
          game.ReplicatedStorage.SoulsEvent:FireClient(Player)
           wait(0.1) 
           script:remove() 
         end 
      end 
      end 
    end 
  Humanoid.Died:connect(kill) 
  2nd Local Script:
  local player = game.Players.LocalPlayer
  game.ReplicatedStorage.SoulsEvent.OnClientEvent:Connect(function()
  player.PlayerGui.ScreenGUI.Soul.Visible = true
  end)

remove the player as an argument i have handled this issue by remove the player as an argument because roblox automatically provides of who fired it then put player as the first parameter of the event

The server fired the event tho.

does not matter tho

30char

i still have the same error :frowning:

It does.
Here:
https://developer.roblox.com/en-us/api-reference/event/RemoteEvent/OnClientEvent

Parameters are just the arguments passed, not the Player. (OnClientEvent)

If he used OnServerEvent then it would work. As the Player Parameter gets passed there automatically.

https://developer.roblox.com/en-us/api-reference/event/RemoteEvent/OnServerEvent

if i dont make sense but if you already passed the argument form the server so should just get it from the client as the parameter

Wouldn’t work as Humanoid.Parent is the NPC character.

Is the Tag an object value with the Player who killed the NPC as value?