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

"player argument must be a player object."?

Asked by
MrHerkes 166
5 years ago
Edited 5 years ago
--Server Script
local tool = script.Parent
local clickEvent = tool:WaitForChild("ClickEvent")
local localTrip = game.ReplicatedStorage:WaitForChild("LocalTripEvent")
local clickEventConnection

local function onEquip()
    clickEventConnection = clickEvent.OnServerEvent:Connect(function(player)
        local hitbox = Instance.new("Part", player.Character)
        hitbox.CanCollide = false
        hitbox.Size = Vector3.new(3,1,2)
        hitbox.CFrame = player.Character.PrimaryPart.CFrame + (player.Character.PrimaryPart.CFrame.lookVector*3 + Vector3.new(0,1,0))
        hitbox.Transparency = 0.5
        game:GetService("Debris"):AddItem(hitbox, 0.1)
        hitbox.Touched:Connect(function(part)
            if part.Parent == player.Character then return end
            local human = part.Parent:FindFirstChild("Humanoid")
            if human then
                localTrip:FireClient(human.Parent.Parent)
                hitbox:Destroy()
            else
                hitbox:Destroy()
            end
        end)
    end)
end

local function onUnequip()
    clickEventConnection:Disconnect()
end

tool.Equipped:Connect(onEquip)
tool.Unequipped:Connect(onUnequip)

--LocalScript
local tool = script.Parent
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local humanoid = player.Character:WaitForChild("Humanoid")
local anim = tool:WaitForChild("PushAnim")
local number = 6
local debounce = false

local clickEvent = tool:WaitForChild("ClickEvent")
local tripEvent = game.ReplicatedStorage:WaitForChild("LocalTripEvent")

local function onActivate()
    if debounce then return end
    debounce = true
    local animtrack = player.Character.Humanoid:LoadAnimation(tool.PushAnim)
        animtrack.Priority = Enum.AnimationPriority.Action
        animtrack:Play()
        animtrack.KeyframeReached:Connect(function(keyframeName)
            if keyframeName == "Push" then
                clickEvent:FireServer()
            end
        end)
    for i=1,5 do
        number = number - 1
        tool.Name = number
        wait(1)
    end
    tool.Name = "Push"
    number = 6
    debounce = false
end

tool.Activated:Connect(onActivate)
tripEvent.OnClientEvent:Connect(function()
    humanoid.Parent.HumanoidRootPart.Velocity = humanoid.Parent.HumanoidRootPart.CFrame.lookVector * -50
    humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
    print("success")
end)

Everytime I run this pushing script, the FireClient() (line 19) sends a error "player argument must be a player object". How do I fix this?

0
humanoid.Parent.Parent is the workspace. User#19524 175 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

The Humanoids Parent’s Parent is the Workspace. To get the player on line 19:

local Players = game:GetService"Players"
local Player = Players:GetPlayerFromCharacter(humanoid.Parent)

if Player then
    localTrip:FireClient(Player)
end

Out of curiosity, why did you try to send the Workspace as an argument?

1
I was just confused. MrHerkes 166 — 5y
Ad

Answer this question