Animation Errors

local holding = script.Parent.Holding
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=16571466944"
repeat wait() until game:GetService("Players").LocalPlayer.Character.Humanoid

if script.Parent.Equipped then
	game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(animation):Play()
end

if script.Parent.Unequipped then
	animation:Stop()
end

This is my first time using proper animations.
I get these errors:
StarterPack.BatteringRam.Script:4: attempt to index nil with ‘Humanoid’
Stop is not a valid member of Animation “Animation”
I’m going to be honest, I have no clue why this happens.
image
I may seem annoying for not looking into documentation(I did, wasn’t so helpful)

2 Likes

lol i was getting same errors when i was really really beginner on scripting animations so i feel you. you should do it like

local animtrack = game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(animation)
if script.Parent.Equipped then
	animtrack:Play()
end

if script.Parent.Unequipped then
	animtrack:Stop()
end
1 Like

thanks for knowing the pain.
but, i either way had to completely change the script, because i needed to add a new functions for something! but, i’m in middle of fixing it right now, so ill use this script to help. thanks btw!

2 Likes

also can you tick it as solved after checking?

1 Like

i think you should put the LoadAnimation:(animation) in a variable like

local Animation = Humanoid:LoadAnimation(animation)

then you could do Animation:Stop()

This should work(correct me if im wrong)

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local Humanoid = character:WaitForChild("Humanoid")

local holding = script.Parent.Holding
local animation = Instance.new("Animation")
animation.AnimationId = ""-- your animation id

local Anim = Humanoid:LoadAnimation(animation)

if script.Parent.Equipped then
	Anim:Play()
end

if script.Parent.Unequipped then
	Anim:Stop()
end
1 Like

@How4rdy
none of these responses ended up helping(to be honest), but the issue was very simple, and just something i somehow did not notice!
it had to be: script.Parent.Equipped:Connect(function()
instead of: if script.Parent.Equipped then

but thanks for trying :slight_smile:

oh sorry i guess i was wrong my bad

This script ended up fixing it:

local holding = script.Parent.Holding
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=16602882758"
repeat wait() until game:GetService("Players").LocalPlayer.Character and game:GetService("Players").LocalPlayer.Character:FindFirstChild("Humanoid")
local animationload	= game:GetService("Players").LocalPlayer.Character.Humanoid.Animator:LoadAnimation(animation)

script.Parent.Equipped:Connect(function()
	animationload:Play()
end)

script.Parent.Unequipped:Connect(function()
	animationload:Stop()
end)

Thanks for everyone who tried!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.