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

animation is not playing with tool equip? SOLVED

ok so my animation is not playing when i equip a tool and i click, i want a animation to play, yet it isnt, any reason why?

local Players = game:GetService("Players")

script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()

local Players = game:GetService("Players")


local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
wait(1.2)
animation:Play()

end)
end)

1 comment

0

thank you to those for your help everyone i finally found out the reason why it wasnt working, i was in r15, the animation was for only r6, thank you to those who helped!

4 answers

Why are you waiting for wait(1.2)?

Just play the animation right after:

local Players = game:GetService("Players")
 
local animation = game.Players.LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid"):LoadAnimation(script.Parent.Animation)

script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()

		local Players = game:GetService("Players")
 
 
		animation:Play()
	end)
end)

Also make your animation priority in the editor to action: other action animations will still override this, so its safe to set equip (and other things) animations to action

EDIT: i fixed so it waits for the humanoid

3 comments

0

ok i will try this

0

i did set the animation to priority, i am getting a error Players.NightGOD3457.Backpack.Spagetti.LocalScript:3: attempt to index nil with 'Humanoid'

0

what this guy said ^^^

****Try changing

game.Players.LocalPlayer.Character.Humanoid

to this

game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

****Update

1 comment

0

nope getting another error Players.NightGOD3457.Backpack.Spagetti.LocalScript:3: attempt to index nil with 'WaitForChild'

Your problem may be the fact that this script is running before your character has loaded.

So, you would do something like this :

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')

local animation = hum:LoadAnimation(script.Parent.Animation)

script.Parent.Equipped:Connect(function(mouse)

mouse.Button1Down:Connect(function()
wait(1.2)
animation:Play()
end)

end)

3 comments

0

Also, make sure this is a Local script

0

nope didnt work

0

im not getting any errors tho, its just not working

thanks for your help everyone i finally found out the reason why it wasnt working, i was in r15, the animation was for only r6, thank you to those who helped!

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