Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

FireClient: player argument must be a Player object?

I get this error FireClient: player argument must be a Player object idk how to fix it i've been trying but i cant seem to fix is i would appreciate if someone helps.

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) 

1 comment

0

How do you accept the manual chore of deleting indentation that is specifically automated, for the central purpose of making readable code?

2 answers

✓ Accepted answer

Simply, firing clients must have a player instance as the first argument. Tag.Parent is the Humanoid, so you have to either use Tag.Parent.Parent (for any part which is a child of the character) or Tag.Parent.Parent.Parent (if hit is an accessory). However, I'd prefer the code below.

local Player = game.Players:FindFirstChild(Tag.Parent.Parent.Name)
if not Player then
      Player = game.Players:FindFirstChild(Tag.Parent.Parent.Parent.Name)
end

if Player then
	game.ReplicatedStorage.SoulsEvent:FireClient(Player)
else
	warn('No player object found')
end

3 comments

0

pls upvote i want professor

0

Sure no problem ill give you an upvote but it says No Player Object found so the code still doesent work.

0

Nvm i cant give an upvote apparently i need 25+ reputation

If anyone needs the same thing i got it to work now

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 = Tag.Value 
		   game.ReplicatedStorage.SoulsEvent:FireClient(Player)
           wait(0.1) 
           script:remove() 
         end 
      end 
   end 
end 

Humanoid.Died:connect(kill) 

This discussion is preserved as it was. New answers, comments, and votes are closed.