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

Making a tool, why is my localscript not animating a player in FE?

Asked by 5 years ago

Hey there,

This is my first post, please be gentle

I'm a somewhat moderate scripter trying to make a simple knife script. I've been working on the local script first. In play solo it works fine, but when I hit run I get an error!

Humanoid is not a valid member of Model

Here is the script:

-- Made by Chardinok no steal por favor

-- Variables
local tool = script.Parent
local plr = game:GetService("Players").LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local hum = chr.Humanoid
print(hum)
local animating = false

-- Animations
local stabanim = Instance.new("Animation")
stabanim.AnimationId = "rbxassetid://2306972447"

tool.Activated:connect(function()
    if animating == false then
        animating = true
        local stabtrack = hum:LoadAnimation(stabanim)
        stabtrack:Play()
        wait(0.5)
        stabtrack:Stop()
        animating = false
    end
end)

I appreciate every response.

0
Just saying I have school tomorrow, I won't be able to respond to anything for pretty much the whole day. Chardinok 5 — 5y
0
The problem is that you are trying to reach `Humanoid` before it loads in, so just change line 7 to `chr:WaitForChild("Humanoid") Pojoto 329 — 5y
0
Thanks, I’ll try that when I get home from school tomorrow! Chardinok 5 — 5y
0
:wait is deprecated use :Wait, and :connect is also deprecated so use :Connect User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Thanks to pojoto I've figured it out!

Instead of local hum = chr.Character, I used local hum = chr:WaitForChild("Humanoid"), and surprisingly, it worked!

Thanks to everyone that helped!

Ad

Answer this question