Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

4 comments

0

Just saying I have school tomorrow, I won't be able to respond to anything for pretty much the whole day.

0

The problem is that you are trying to reach Humanoid before it loads in, so just change line 7 to `chr:WaitForChild("Humanoid")

0

Thanks, I’ll try that when I get home from school tomorrow!

0

:wait is deprecated use :Wait, and :connect is also deprecated so use :Connect

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.