Remote event error

i am trying to create a sword that has an animation when you press e (e is the heavy move), the heavy move itself works except the remote event that should be making the sword actually animate does not

the error im getting is “FireClient: player argument must be a player object”

here is the script (in studio it has indents and stuff but it got reformatted when i pasted it here)

local tool = script.Parent
local character = tool.Parent
local player = game:GetService(“Players”).LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild(“SwordE”)

local debounce = false
remoteEvent.OnServerEvent:Connect(function()
if not debounce then
end
local Source = script.Parent.Source
for count = 1, 1 do
remoteEvent:FireClient(player)
local result = workspace:Raycast(Source.Position, Vector3.new(0, 0, 5))
if result then
local character = result.Instance.Parent
local humanoid = character:FindFirstChild(“Humanoid”)
if humanoid and humanoid ~= tool.Parent.Humanoid then
humanoid:TakeDamage(35)
debounce = true
wait(6)
debounce = false
end
end
end
end)

1 Like

Is this script a LocalScript? You aren’t supposed to use RemoteEvent.OnServerEvent in a LocalScript or Players.LocalPlayer in a ServerScript

3 Likes

this is a server script but there’s a local script that detects when the client presses e and then it fires the event in this script

Doesn’t that mean in the local script you’re gonna have to use remoteEvent:FireServer() instead of FireClient()?

Remove fire client if you have nothing to fire to the client. (Edit)

It should be OnServerEvent because You cant use FireClient on a localscript as what i know.

1 Like

Can I see what you put on the local script that detects when e is pressed?

Players.LocalPlayer is not usable in a server-side script, ergo setting your player variable to Players.LocalPlayer will not give you a Player instance, ergo you can’t use your player variable as an argument in :FireClient()

You shouldn’t use Players.LocalPlayer in a ServerScript, but rather getting the Player object with RemoteEvent.OnServerEvent instead because the first parameter that the event give is the Player object.

remoteEvent.OnServerEvent:Connect(function(player)
Forgot OnServerEvent has player args?

it does fire the server in the local script though

i should probably have specified which line is causing the error, everything else is fine, “remoteEvent:FireClient()” (Line 11) is the one which is causing the error

I’m not an expert of remote events but try placing player in OnServerEvent:Connect(function() instead.
You see, OnServerEvent works just like PlayerAdded, PlayerRemoving, MouseClick and Triggered because the parameter they use is assigned to the player.

Alrighty, let’s do some magic. First of all, game.Players.LocalPlayer can only be called from a LocalScript, (because it is ran on your client), so always remember LocalPlayer in LocalScript. Second, OnServerEvent always has a player argument being passed to it, no matter what. So you can actually just use this:

local tool = script.Parent
local character = tool.Parent
local remoteEvent = game.ReplicatedStorage:WaitForChild(“SwordE”)

local debounce = false
remoteEvent.OnServerEvent:Connect(function(player)
    if debounce then return end

    local Source = script.Parent.Source

    for count = 1, 1 do
        remoteEvent:FireClient(player)

        local result = workspace:Raycast(Source.Position, Vector3.new(0, 0, 5))
        
        if result then
            local character = result.Instance.Parent
            local humanoid = character:FindFirstChildOfClass(“Humanoid”)

            if humanoid and humanoid ~= tool.Parent.Humanoid then
                humanoid:TakeDamage(35)
                debounce = true
                wait(6)
                debounce = false
            end
        end
    end
end)

Lastly, if you need anything else regarding this thread, I’m here to help! And if this does end up working for you, if you would be so kind as to mark me as the solution, that would be amazing! With that being said, you have an amazing rest of your day/night! :slightly_smiling_face:

2 Likes