FireClient: player argument must be a Player object

Hi. I’m making a football game where the score changes when someone scores (obsiously)

But when I fire the remote events for changing the scoreboard, this error occurs:

FireClient: player argument must be a Player object

This is my script:

while true do
	wait(0.5)
	
	script.Parent.Touched:Connect(function(hit)
		if hit.Name == "Ball" then
			game.Workspace.RedPoint:FireClient(hit)
		end
	end)
end

It’s in a serverscript

The issue is that your trying to use :FireClient() with not a player. “Ball” is not a player but rather a part instance I am guessing or a mesh.

Did you meant to use :FireAllClients() which fires all clients rather then just one?

2 Likes

You don’t need to put the connection into a while loop you can connect it once.And use RemoteEvent:FireClient(player,args…).
Hit argument doesn’t returns a player character instead it returns the instance that touched it.To get a player character,you can use

local PlayerCharacter = hit:FindFirstAncestorOfClass(“Model”) – will return the first
parent which is a model
if not PlayerCharacter then return end – stop if no model instance found

then to get player

local Player = game.Players:GetPlayerFromCharacter(PlayerCharacter) – will get the player by char model
if not Player then return end – stop if model isnt a player char

now you can fire event to client by

yourRemoteEvent:FireClient(Player,yourArgs)

This code will not work in the code the player has sent? If you check the code that @DanielosthebestYTAlt presented in this post, you can see that there is an if statement checking if the item which was hit is called “Ball” meaning that it is clearly not a player/character which is being touched.

My guess that this .Touched event is inside of the goal and when a goal happens they wish for all the clients to update the score (or at least that is what the code looks like). I don’t see why the user would even need to get the player if this is the use case of this code. Even if they needed the player who scored for like a notification system, the best way would probs to have a value in the ball which contains the last player who kicked it so that the code can detect who scored it rather then trying to get the player from the hit part which from my guess will never have a player unless it is due to a kick or something.

Oh I tought he was trying to fire a event to client that touches a instance.
Probably he should just use remoteEvent:FireAllClients()

1 Like

You are not firing the event to the correct player.
game.Workspace.RedPoint:FireClient(hit)
hit is a part, which is not a player.
if hit.Parent is a player, then you could use:
game.Workspace.RedPoint:FireClient(hit.Parent)