I have been scripting for a little over six months and have been wanting to deeper familiarize myself with the concept of scripting animations - specifically, gun animations.
What do you want to achieve?
I would like to learn how to make an idle gun animation.
What is the issue?
Every time I load an animation, the character’s idle animation overrides it. I have tried to set the priority of the animation in the animation editor before exporting it but it does not seem to work.
What solutions have you tried so far?
I have watched TheDevKings’s video on animations but his also gets overridden.
What do I do? Is it still a problem with the priority? Must I change the animation priority via a Script, with an Enum or something? All responses are well appreciated.
Usually whenever you want to create an animation, you should set the AnimationPriority property to Action (Or something that’s higher than Core) so that it’s able to override all the other default animations & you should use the Humanoid’s Animator object to load the animations
local Tool = script.Parent
local IdleAnim = Tool:WaitForChild("IdleAnim")
Tool.Equipped:Connect(function()
local Character = Tool.Parent
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local LoadAnim = Animator:LoadAnimation(IdleAnim)
LoadAnim:Play()
end)
Do make sure that the animation that you are playing is owned by you, and that you’re able to access it easily
I added a while loop to play the animation whilst the tool is equipped and to stop when its unequipped. However, when I walk, it looks a bit weird. The character default walk animation overrides the gun animation. What should I do? Is it best to make my own walk animation? Here is my code.
local tool = script.Parent
local IdleAnim = tool:WaitForChild("IdleAnim")
local playAnim
tool.Equipped:Connect(function()
playAnim = true
local character = tool.Parent
local animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
local loadAnim = animator:LoadAnimation(IdleAnim)
while playAnim do
wait()
loadAnim:Play()
end
end)
tool.Unequipped:Connect(function()
playAnim = false
end)
Although this would work, I wouldn’t recommend encasing loops inside Equipped events
Instead you can create a couple of local variables outside the Events:
local tool = script.Parent
local IdleAnim = tool:WaitForChild("IdleAnim")
local Character
local animator
local loadAnim
tool.Equipped:Connect(function()
Character = tool.Parent
animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
loadAnim = animator:LoadAnimation(IdleAnim)
loadAnim:Play()
end)
tool.Unequipped:Connect(function()
loadAnim:Stop()
end)
I don’t know how much about how animation welds work, but I believe what you could use is Motor6D’s instead, and create your own walk animation? So yes
Don’t put the code in a loop, just play it once. If the priority is Idle, it will just stay idle until the player moves, and when they stop, it will just play again.