Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone help with this error "FireClient: player argument must be a Player object"?

Asked by 2 years ago

I need help fixing this error. I don't think the remote event will take "player".

The error is "FireClient: player argument must be a Player object"

Here is the script

local part = script.Parent
local player = game.Players.LocalPlayer

local debounce = false

part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
    if debounce == false then
        debounce = true
        game.ReplicatedStorage.GreenArrow:FireClient(player)
    end
end)
0
Is this a LocalScript or a Script? In Script, not LocalScript, game.Players.LocalPlayer is nil. local player = game.Players:GetPlayerFromCharacter(hit.Parent) 9mze 193 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

You can't use localplayer from a serverscript, and if this is a localscript, you cant fireclient from a localscript.

This code will work

local PlayersService = game:GetService("Players")

local Remote = your.path.to.remote


part.Touched(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local Character = humanoid.Parent
        local Player = PlayersService:GetPlayerFromCharacter(Character)
        Remote:FireClient(Player)
    end
end)
0
thanks but i think i fixed it by adding game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) mintywintytinty 2 — 2y
Ad

Answer this question