Help with Idle and Attack Animation Tool!

Hey developers! I am currently trying to work on my Melee tools using RaycastHitboxV4 and while trying to use animations apparently my Attack animation isn’t working as the Idle animation literally overlaps it, I need some help if you can, and another problem is that when I equip the tool and activated it and instantly unequip it, it shows a error that “Humanoid isn’t a valid member of Backpack” and the tool just breaks after that. I just need help on how can I make it so that the Idle animation stops when I activate my Attack animation and let the Idle animation continue when the Attack animation finishes, oh and to stop that error of “Humanoid isn’t a valid member of Backpack.” Any help is appreciated! In total I have 2 problems.

local RayCastHitBox = require(game.ServerScriptService.RaycastHitboxV4)
local DAMAGE = math.random(45,55)
local COOLDOWN = 0.1
local DEBOUNCE = false
local HitSound = script.Parent.Handle.Hit
local SwingSound = script.Parent.Handle.Swing
--local Humanoid = script.Parent:WaitForChild("Humanoid")
local Used = false
local IdleAnim = Instance.new("Animation")
IdleAnim.AnimationId = "rbxassetid://8688571269"
local IdleTrack

local AttackAnim = Instance.new("Animation")
AttackAnim.AnimationId = "rbxassetid://8689271319"
local AttackTrack

local Hitbox = RayCastHitBox.new(script.Parent.Handle)
Hitbox.Visualizer = false

script.Parent.Equipped:Connect(function()
	wait(0.01)
	IdleTrack = script.Parent.Parent.Humanoid:LoadAnimation(IdleAnim)
	if script.Parent.Parent.Humanoid ~= nil then
	IdleTrack.Priority = Enum.AnimationPriority.Action
	IdleTrack.Looped = true
		IdleTrack:Play()
	else
		
	end
end)

script.Parent.Activated:Connect(function()
	if DEBOUNCE == false then
		DEBOUNCE = true
		wait(0.01)
		SwingSound:Play()
		AttackTrack = script.Parent.Parent.Humanoid:LoadAnimation(AttackAnim)
		if script.Parent.Parent.Humanoid ~= nil then
		AttackTrack.Priority = Enum.AnimationPriority.Action
		AttackTrack.Looped = false
		AttackTrack:Play()
		Hitbox:HitStart(0.8)
		wait(COOLDOWN)
			DEBOUNCE = false
			
		else
			
			end
		end
end)

Hitbox.OnHit:Connect(function(Part, Humanoid)
	if Humanoid and Humanoid ~= script.Parent.Parent.Humanoid then
		Humanoid:TakeDamage(DAMAGE)
		HitSound:Play()
	end
end)

script.Parent.Unequipped:Connect(function()
	wait(0.01)
	if IdleTrack then
		IdleTrack:Stop()
	if AttackTrack then
		AttackTrack:Stop()
		end
	end
end)

Here’s also a crappy video I made on the animation glitch or bug, you name it.
robloxapp-20220130-2231260.wmv (2.6 MB)

What is the animation priority for the idle animation
https://developer.roblox.com/en-us/api-reference/property/AnimationTrack/Priority

  • This property sets the priority of an AnimationTrack . Depending on what this is set to, playing multiple animations at once will look to this property to figure out which Keyframe Pose s should be played over one another.

The animation priority is action, just how it says on the script

When you’re animating a single instance with multiple animation tracks you need to stop any ongoing animation track before you intend to start playing some other animation track otherwise the tracks will play over each other.

1 Like

Oh yeah that was the problem but I forgot to close this topic but I ran into another problem and it’s that when I equip the tool and activated it and instantly unequip it, it shows a error that “Humanoid isn’t a valid member of Backpack” and the tool just breaks after that.
Do you mind helping me with that?

local SSS = game:GetService("ServerScriptService")
local Module = SSS.RaycastHitboxV4
local RayCastHitBox = require(Module)

local Tool = script.Parent
local Handle = Tool.Handle
local HitSound = Handle.Hit
local SwingSound = Handle.Swing

local Player = Tool:FindFirstAncestorOfClass("Player")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local IdleAnim = Instance.new("Animation")
IdleAnim.AnimationId = "rbxassetid://8688571269"
IdleAnim.Parent = script
local IdleTrack

local AttackAnim = Instance.new("Animation")
AttackAnim.AnimationId = "rbxassetid://8689271319"
AttackAnim.Parent = script
local AttackTrack

local Hitbox = RayCastHitBox.new(Handle)
Hitbox.Visualizer = false

local Debounce = false

Tool.Equipped:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if Humanoid then
		if AttackTrack then
			AttackTrack:Stop()
		end
		if not IdleTrack then
			IdleTrack = Humanoid:LoadAnimation(IdleAnim)
			IdleTrack.Priority = Enum.AnimationPriority.Action
			IdleTrack.Looped = true
			repeat task.wait() until IdleTrack.Length > 0
		end
		IdleTrack:Play()
	end
end)

Tool.Activated:Connect(function()
	if Debounce then
		return
	end
	Debounce = true
	task.delay(0.1, function()
		Debounce = false
	end)
	
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if Humanoid then
		if IdleTrack then
			IdleTrack:Stop()
		end
		if not AttackTrack then
			AttackTrack = Humanoid:LoadAnimation(AttackAnim)
			AttackTrack.Priority = Enum.AnimationPriority.Action
			AttackTrack.Looped = false
			repeat task.wait() until IdleTrack.Length > 0
		end
		AttackTrack:Play()
		SwingSound:Play()
		Hitbox:HitStart(0.8)
	end
end)

Hitbox.OnHit:Connect(function(HitPart, HitHumanoid)
	if not HitHumanoid then
		return
	end
	
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	
	if not Humanoid then
		return
	end
	
	if HitHumanoid ~= Humanoid then
		HitHumanoid:TakeDamage(50)
		HitSound:Play()
	end
end)

Tool.Unequipped:Connect(function()
	if IdleTrack then
		IdleTrack:Stop()
	end
	if AttackTrack then
		AttackTrack:Stop()
	end
end)

I’m not too familiar with the module being used but if you encounter any errors please share the error message/line number, thanks.

1 Like