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

"FireClient: player argument must be a Player object" Error?

Asked by 4 years ago

This question has been solved by the original poster.

My Idle animation won't stop working because my getPlayer function won't get the actual player? I'm not sure why it won't get the player!?

Serverscript in tool

local Tool = script.Parent
local Remote = Tool:WaitForChild("Remote")
local Handle = Tool:WaitForChild("Handle")
local Mesh = Handle:WaitForChild("Mesh")



local Equipping = false
local Grip = nil

local StraightMeshData = "http://www.roblox.com/asset/?id=193827643"
local StraightGripPos = Vector3.new(0, 0, 1.5)
local BentMeshData = "http://www.roblox.com/asset/?id=193827593"
local BentGripPos = Vector3.new(0, 0.6, 0.5)
local Bent = true

local AttackAble = true
local AttackRestTime = 1
local AttackVictims = {}
local AttackWindow = 0.66
local AttackDamaging = false
local AttackWindup = 0.1

function getPlayer()
    local char = script.Parent.Parent
    return game:GetService("Players"):GetPlayerFromCharacter(char)
end

function contains(t, v)
    for _, val in pairs(t) do
        if val == v then
            return true
        end
    end
    return false
end

function tagHuman(human)
    local tag = Instance.new("ObjectValue")
    tag.Value = getPlayer()
    tag.Name = "creator"
    tag.Parent = human
    game:GetService("Debris"):AddItem(tag)
end

function normal()

    if not AttackAble then return end

    --rest
    AttackAble = false
    delay(AttackRestTime, function()
        AttackAble = true
    end)

    --damage
    delay(AttackWindup, function()
        AttackVictims = {}
        AttackDamaging = true
        delay(AttackWindow, function()
            AttackDamaging = false
        end)
    end)

    Handle.Swing:Play()

    local t = math.random(1, 2)
    if t == 1 then
        Remote:FireClient(getPlayer(), "PlayAnimation", "Swing1")
        Handle.Trail.Enabled = true
    elseif t == 2 then
        Remote:FireClient(getPlayer(), "PlayAnimation", "Swing2")
        Handle.Trail.Enabled = true
    end

end

function onEquip()
    if Equipping then return end
    Equipping = true

    --animation
    Remote:FireClient(getPlayer(), "PlayAnimation", "Idle")
    Handle.Trail.Enabled = false
    Equipping = false
end

function onUnequip()
    if Grip then
        Grip:Destroy()
    end

    --animation
    Remote:FireClient(getPlayer(), "StopAnimation", "Idle")
end

function onRemote(player, func, ...)
    if player ~= getPlayer() then return end

    if func == "NormalStart" then
        normal()
    end
end

Tool.Equipped:connect(onEquip)
Tool.Unequipped:connect(onUnequip)
Remote.OnServerEvent:connect(onRemote)
0
can you try printing out: print(getPlayer()) and then print(getPlayer().Parent) ? royaltoe 5144 — 4y
0
Did you try debugging? Maybe using the print function at certain points in your getPlayer() function? Or after it's called? joshmatt2244 28 — 4y
0
do u even read bruh i just said that royaltoe 5144 — 4y
0
You asked if you could. I said you can. Stop being arrogant, you came here for answers, your script is messy and it hurts my eyes to read it. If you want to solve your issue, learn to script like everyone who scripts did. It's called reading the roblox developer API page :) joshmatt2244 28 — 4y
View all comments (4 more)
0
Oops, sorry. I'm not the original poster. I also meant the 'do u even read' comment sarcastically since I already told him to try printing but, bad wording by me and you explained well. Srry. royaltoe 5144 — 4y
0
I fixed it Jomeliter 55 — 4y
0
yay royaltoe 5144 — 4y
0
please let ppl know what you did to fix it in the comments or answer tab. i'll mark your solution as the answer. royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I fixed this error by changing the GetPlayer() to script.Parent.

Ad

Answer this question