Hey, i made this script for fire to a player only
But its giving me this error
FireClient: player argument must be a Player object
This is my script
local remote = game.ReplicatedStorage.TimeToOpenDoor
local Sensor = script.Parent.Sensor
local plr = game.Players.LocalPlayer
Sensor.Touched:Connect(function(hit)
remote:FireClient(plr)
end)
Is this a regular script or a localscript? Judging from the error, it’s a regular script. You can’t use LocalPlayer in a regular script, you need to get the player differently, which is simple, GetPlayerFromCharacter
Try this
local remote = game.ReplicatedStorage.TimeToOpenDoor
local Sensor = script.Parent.Sensor
Sensor.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then return end
remote:FireClient(plr)
end)
You can’t access a Local Player from a server script, also you might want to do some checks inside that touched event or you would just be spamming the client.