Getting the error: FireClient: player argument must be a Player object please help

Hello! I am Dev_Asher and I am working on a find the markers game remake, I made a script where when the player touched a marker or in this case Bunny, it fires a remote event to the client where it will reward the player for finding the Bunny. But now when I Fire the client it gives me an error saying FireClient: player argument must be a Player object. Does anyone know how to fix this?

local ReplicatedService = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')


local BunnyFolder = WorkspaceService:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedService:WaitForChild('Modules'))
local BunnyRarityModule = ReplicatedModules.Bunnys
local RemoteModule = ReplicatedModules.RemoteService

local BunnyTouchedEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

local LocalPlayer = Players.LocalPlayer

local Module = {}

function Module:CheckBunny()
	for i, Bunny in pairs(BunnyFolder:GetChildren()) do
		if Bunny:IsA('Part') and Bunny.Parent == BunnyFolder then
			Bunny.Touched:Connect(function(Hit)
				BunnyTouchedEvent:FireClient(LocalPlayer, Bunny)
				print(Hit.Name)
			end)
		else
			warn('Touched Part Not From Bunny Folder')
		end
	end
end

Module:CheckBunny()

return Module

Right now I think it is because It is a server script, I changed it into a local script and deleted the Local Module = {} and the return Module but it did not work.

its meant to be a server script but you cant use localplayer in a sever script because the server is not a player

or i think its ment to be a server script because

you use FireClient in server scripts and FireServer in localscripts

1 Like

It is meant to be a client script.

I put it in starter player scripts and now nothing is happening. No errors no prints nothing?

then you need to be using FireServer and dont need to pass the localplayer because roblox sends that automatically

maybe this article will help you

Thanks alot, I am going to try it now so I shall see if it works.

it wont work because it looks like it needs to be a module

Still nothing is happening it is not printing and yes it is a module.

The error is because the modulescript is required in a server script and in a server script, LocalPlayer is nil. Try to do it in a LocalScript. Also, for local scripts, FireServer(...) should be used.

do you have another script that is doing

local modulescript = require(game.xxxxx.ModuleScript)
modulescript:CheckBunny()

maybe this article will help you

Still Nothing here is my code for the local script

local ReplicatedService = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')

local SystemsContainer = {  }

local BunnyFolder = WorkspaceService:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedService:WaitForChild('Modules'))
local BunnyRarityModule = ReplicatedModules.Bunnys
local RemoteModule = ReplicatedModules.RemoteService

local BunnyTouchedEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

local LocalPlayer = Players.LocalPlayer

local function CheckBunny()
	for _, Bunny in ipairs(BunnyFolder:GetChildren()) do
		if Bunny:IsA('Part') and Bunny.CanTouch == true then
			Bunny.Touched:Connect(function()
				print('Bunny Touched')
				BunnyTouchedEvent:FireServer(Bunny)
			end)
		else
			warn('Touched Part Not From Bunny Folder')
		end
	end
end

CheckBunny() ```
local ReplicatedService = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')


local BunnyFolder = workspace:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedService:WaitForChild('Modules'))
local BunnyRarityModule = ReplicatedModules.Bunnys
local RemoteModule = ReplicatedModules.RemoteService

local BunnyTouchedEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

local Module = {}

function Module:CheckBunny()
	for i, Bunny in pairs(BunnyFolder:GetChildren()) do
		if Bunny:IsA('Part') and Bunny.Parent == BunnyFolder then
			Bunny.Touched:Connect(function(Hit)
                local LocalPlayer = Players:GetPlayerFromCharacter(Hit.Parent)
				BunnyTouchedEvent:FireClient(LocalPlayer, Bunny)
			end)
		else
			warn('Touched Part Not From Bunny Folder')
		end
	end
end

Module:CheckBunny()

return Module

I also have the variable of bunny folder and a workspace variable just forgot to paste those lol

I tried that but still nothing is printing :frowning:

The touched event will not work in Local Scripts.

Do touched on the server then fire the client that touched it. Then award them.

I made it a Module script still nothing :frowning:

I also put it in server script service. Should I put it in starter player scripts?

What you need to do is:

  • Create a serverscript
  • Handle .touched event (you should require bunny module and run CheckBunny function!)
  • Award the player who touched.

If you require a module in a localscript and try to use the touched event, it will not work as touched event only works in server scripts!

1 Like