FireClient: player argument must be a Player object. Why does it happen?

So im making a racing game and using a remote event to start the cooldown that is fired when the player gets in the car. Though when i try to write it i get the error mentioned in the title.

Here is the script:

Server:

local remoteEvent = game.ReplicatedStorage:WaitForChild("CooldownEvent")

local function fireToLocalPlayer(player)
	remoteEvent:FireClient(player)
end


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		fireToLocalPlayer(player)
	end
end)

Local Script:

local remoteevent = game.ReplicatedStorage.CooldownEvent

remoteevent.OnClientEvent:Connect(function()
	print"CoolDownEvent Recieved"
end)
1 Like

Your code is incomplete. What does the player of fireToLocalPlayer(player) from?

2 Likes

Oh, missed that when pasting. It is
local player = game.Players.LocalPlayer

I mean your server script.

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		fireToLocalPlayer(player) -- from what?
	end
end)
2 Likes

will something like this work?

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if seat.Occupant then
        local player = seat.Occupant 
        fireToLocalPlayer(player) 
    end
end)
1 Like

Try this

local seat = script.Parent


local Players = game:GetService("Players")
local remoteEvent = game.ReplicatedStorage:WaitForChild("CooldownEvent")

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
		print(Player.Name)
		
		
		remoteEvent:FireClient(Player)
	end
end)
2 Likes

For future reference, LocalPlayer is nil when used in server-side scripts, which is why your original script didn’t work :slight_smile::+1:

1 Like

Works great! Thank you so much!

1 Like

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