Error: 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!

I am trying to make it so that if you equip a tool such as a gun in a vehicle, you peak out the window. I’m using remotes and animations

  1. What is the issue? Include screenshots / videos if possible!

ServerScript:

local seat = script.Parent
seat.Changed:Connect(function()
	if seat.Occupant ~= nil then
		local char = seat.Occupant
		char.Parent.ChildAdded:Connect(function(tool)
			if tool:IsA("Tool") then
				local player = game.Players:GetPlayerFromCharacter(char)
				game.ReplicatedStorage.RightPeak:FireClient(player)
			end
		end)
	end
end)

LocalScript:

local char = script.Parent
local plr = game.Players.LocalPlayer
RightAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild('PeakCar'))


game.ReplicatedStorage.RightPeak.OnClientEvent:Connect(function(player)
	RightAnim:Play()
end)

The error I am getting is:

FireClient: player argument must be a Player object

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried looking the error up and modifying the script multiple times but to no luck it still didn’t work. If anybody could tell me what is wrong it would be really appreciated!

Your server script doesn’t check if the function was able to get a player.

if tool:IsA("Tool") then
	local player = game.Players:GetPlayerFromCharacter(char)

    if player then
	    game.ReplicatedStorage.RightPeak:FireClient(player)
    end
end

The function returns nil if it wasn’t able to get a player.


Yea, that might be the issue

1 Like

I think that the problem is that the seat’s occupant is the humanoid, not the character. But like @HugeCoolboy2007 said you should also check that the player does exist

local seat = script.Parent
seat.Changed:Connect(function()
	if seat.Occupant ~= nil then
		local char = seat.Occupant.Parent
		char.Parent.ChildAdded:Connect(function(tool)
			if tool:IsA("Tool") then
				local player = game.Players:GetPlayerFromCharacter(char)
                if player then
			      	game.ReplicatedStorage.RightPeak:FireClient(player)
                end
			end
		end)
	end
end)
3 Likes

Thank you, I realized that the seat occupants was the humanoid and not the actual character, now everything works fine! :grin:

1 Like