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

animation is not playing with tool equip? SOLVED

Asked by 4 years ago
Edited 4 years ago

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)

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! NightGOD3457 0 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

0
ok i will try this NightGOD3457 0 — 4y
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' NightGOD3457 0 — 4y
0
what this guy said ^^^ elitekiller2342 87 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

****Try changing

game.Players.LocalPlayer.Character.Humanoid

to this

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

****Update

0
nope getting another error Players.NightGOD3457.Backpack.Spagetti.LocalScript:3: attempt to index nil with 'WaitForChild' NightGOD3457 0 — 4y
Log in to vote
0
Answered by
Subsz 366 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
Also, make sure this is a Local script Subsz 366 — 4y
0
nope didnt work NightGOD3457 0 — 4y
0
im not getting any errors tho, its just not working NightGOD3457 0 — 4y
Log in to vote
0
Answered by 4 years ago

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!

Answer this question