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.
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.
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