1. For a gun I have made I am trying to create some animations for it!
2. I know that Humaniod:LoadAnimation(Animation Here) is depreciated but can’t figure out how to change my code to the right version
3. I have tried looking around Youtube, Here and DeveloperHub for any help but I didn’t understand it, would love if someone could explain it in simple terms or give a good link .
here is my current code
local tool = script.Parent
local shootAnim = Instance.new("Animation")
shootAnim.AnimationId = "rbxassetid://5940342945"
local track
tool.Activated:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(shootAnim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false
track:Play()
end)
I assume your code already works, correct? This is how to use the new way of playing animations on the client. I recommend looking at the api on dev hub for more info.
local tool = script.Parent
local shootAnim = Instance.new("Animation")
shootAnim.AnimationId = "rbxassetid://5940342945"
local track
tool.Activated:Connect(function()
local animator = script.Parent.Parent.Humanoid:FindFirstChildOfClass("Animator")
if animator then
track = animator:LoadAnimation(shootAnim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false
track:Play()
end
end)
A small note, you should check if the tools parent has a humanoid child to double check that it’s not in the backpack. Otherwise, your code could throw an error. Always nice to be sure.