FireClient: player argument must be a Player object error.How to fix it?

Hi all
I was trying to fire a event on server side but this error popped up:
FireClient: player argument must be a Player object
Even after idefined the player in the script.
The script:

local player = game.Players.LocalPlayer
local Car = game.Workspace.Car
local Destination1 = game.Workspace.Car1
local Destination2 = game.Workspace.Car2

local TweenService = game:GetService("TweenService")
local CarTweenInfo = TweenInfo.new(5, 
									Enum.EasingStyle.Linear,
									Enum.EasingDirection.Out,
									0,
									false,
									0)

local CarTween = TweenService:Create(Car, CarTweenInfo, {CFrame = Destination1.CFrame})
local CarTween2 = TweenService:Create(Car, CarTweenInfo, {CFrame = Destination2.CFrame})

game.ReplicatedStorage.CarTrigger.OnServerEvent:Connect(function()
	CarTween:Play()
	game.Workspace["Car Engine"]:Play()
	game.ReplicatedStorage.CutsceneTrigere:FireClient(player)
	CarTween2:Play()
	wait(4.8)
	game.Workspace["Car Engine"].Looped = false
	game.Workspace["Car Stop 1.1"]:Play()
	script.Parent.Tween.Disabled = true
end)

	


I cant fix this problem and am hoping someone can help.
Thank You

Is this script running on the server?

You can’t get local player on server scripts, you can get the player from the server event

game.ReplicatedStorage.CarTrigger.OnServerEvent:Connect(function(player)

Remote events fired to the server always have a player object as their first argument.

Try:

game.ReplicatedStorage.CarTrigger.OnServerEvent:Connect(function(player)

absolutely no need to repost
OnServerEvent:Connect(function(player)
there, thats how you id the player via server event

When you fire the client, make sure you do:

:FireClient(Player, Argument)

NOT

:FireClient(Argument)

You need the “Player” in there so it knows which client to fire the event to.

Edit could you show the server script too

yes it is running on the sever

Your problem is line 1.

The server cant get the localplayer.

replace this line with this:
game.ReplicatedStorage.CarTrigger.OnServerEvent:Connect(function(player)

The script in this post is the server script

And also i am not getting how to add a argument there as this is a regular function and not a local function.

you can’t use local player in a server script
and the error is from you not setting a variable in your onserverevent function for the player which is the first argument sent over by the client

if any other part of this needs to do something client side you may want to recode it
but here is a version with player declared

--local player = game.Players.LocalPlayer  -- you can't get the local player on the server since there isn't one
local Car = game.Workspace.Car
local Destination1 = game.Workspace.Car1
local Destination2 = game.Workspace.Car2

local TweenService = game:GetService("TweenService")
local CarTweenInfo = TweenInfo.new(5, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0)

local CarTween = TweenService:Create(Car, CarTweenInfo, {CFrame = Destination1.CFrame})
local CarTween2 = TweenService:Create(Car, CarTweenInfo, {CFrame = Destination2.CFrame})

game.ReplicatedStorage.CarTrigger.OnServerEvent:Connect(function(player)  -- when a client fires the server the player is always the first argument sent over to the server you need a variable for it
	CarTween:Play()
	game.Workspace["Car Engine"]:Play()
	game.ReplicatedStorage.CutsceneTrigere:FireClient(player)
	CarTween2:Play()
	wait(4.8)
	game.Workspace["Car Engine"].Looped = false
	game.Workspace["Car Stop 1.1"]:Play()
	script.Parent.Tween.Disabled = true
end)


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.