You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? - I’m trying to make a gun animation when you hold the tool, to replace the default one.
What is the issue? - The script won’t work, there is already an animation.
What solutions have you tried so far? I’ve tried the output and even YouTube videos, still can’t find the problem.
local anims = {script.Parent.HoldAnim, script.Parent.ShootAnim}
local loadedAnims = {}
local tool = script.Parent
local animator
tool.Equipped:Connect(function(mouse)
animator = plr.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
loadedAnims[1] = animator:LoadAnimation(anims[1])
loadedAnims[1]:Play()
end)
tool.Unequipped:Connect(function()
loadedAnims[1]:Stop()
-- I know the ShootAnim isn't written yet, I just need to find the problem for the HoldAnim first.
end)
animator is not in humanoid by default, you must create one.
local anims = {script.Parent.HoldAnim, script.Parent.ShootAnim}
local loadedAnims = {}
local tool = script.Parent
local animator
tool.Equipped:Connect(function(mouse)
local animator
if not plr.Chracter.Humanoid:FindFirstChildOfClass("Animator") then
animator = Instance.new("Animator", plr.Character.Humanoid)
else
animator = plr.Character.Humanoid.Animator -- doing because it would create a new animator every time tool is equipped
end
loadedAnims[1] = animator:LoadAnimation(anims[1])
loadedAnims[1]:Play()
end)
tool.Unequipped:Connect(function()
loadedAnims[1]:Stop()
--- just do shootanim:Play(). It automatically comes back to hold aslong as the hold keyframe is at the end of the animation. No need for anim:Stop()
end)