Somebody please help me out. Having trouble understanding how to re-use animations

Hello Roblox Community your help would be immensly appreciated because I have been working on this for weeks now and it has halted the development of my game.
First off heres what the code looks like:


And here’s what I need changed. So the current script is my attempt at checking if the player has the weapon animations inside of their humanoid Animator but it does not work. I need to know if the player has the animations in their animator already because if I load the animation everytime it will stack up and give me errors. So far I’ve had no luck and considering their are some dang good developers on here I wanna give it a shot. I only showed what I thought neccesary I hope that is enough and please reply!

Tysm for your time, XSpectic

1 Like

Maybe you could do like if not Human.Animator:FindFirstChild(“animName”) then add it y’know and then follow up w the code.

Nah man unfortunately I don’t think the animations have a physical instance inside of the animator. I appreciate the suggestion though, thanks for the reply.

1 Like

Your code is a little confusing. Can you send us the entire script or elaborate (explain) more on what you’re trying to do?

Sure I’ll do both and sorry I din’t know. So basically what I want to do is, have a way to check the players Loaded Animation Tracks so I can know if you already loaded the animations or not. The reason why I wan’t to do this is becaues when I did “Human:LoadAnimation()” everytime I used a track it would start to stack up and eventually reach the limit. So far I’ve made a little bit of progress by using tables but I hit a roadblock again. Hopefully this helps you help me thank you.

--------------------------------------
-- New Melee Weapon Template Client --
--------------------------------------

local tool = script.Parent
local isEquipped = false
local comboTrack1 = nil -- storing these here to be used later on.
local comboTrack2 = nil
local durability = 100 -- tells the script how many times you can hit something with the tool.
local damage = 10 -- this is how much base damage the weapon does not including headshots.
local swingDB = false
local canSwing = false
local loadedAnim
local combo = 1
local animations = {} -- makes a table for the new animations
local isSwinging = false
local canDamage = true
tool.Equipped:Connect(function()
	isEquipped = true
	local char = tool.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	local human = char:FindFirstChildWhichIsA("Humanoid")
	for i, v in pairs(human.Animator:GetPlayingAnimationTracks()) do
		table.insert(animations, v)
		print("Adding Current Animations.")
	end
	local handle  = tool.Handle
	-- Setting up Animations
	if table.find(animations,"equipAnimation") then -- sets up variables and animations, also checks if the player already loaded the animations or not
		print("Found animation preset, loading variables now.")
		animations.MeleeEquip:Play()
		animations.MeleeIdle:Play(1)
		comboTrack1, comboTrack2 = animations.swingAnim1, animations.swingAnim2
		else 
		print("Didn't find a swing animation so anims aren't loaded")
		animations = { human.Animator:LoadAnimation(script.Swing1),
			 human.Animator:LoadAnimation(script.Swing2),
			human.Animator:LoadAnimation(script.MeleeIdle),
			human.Animator:LoadAnimation(script.MeleeEquip)
		}
		animations.MeleeEquip:Play()
		animations.MeleeIdle:Play(1)
		comboTrack1, comboTrack2 = animations.swingAnim1, animations.swingAnim2
	end
	handle.Equip:Play(.1)
	wait(.75)
	canSwing = true
	------------------------------------------------------------------------------------------qq---------------------------------------------------------------
	if comboTrack1 == nil or comboTrack2 == nil then
		warn('one of the combo tracks are nil')
	end
	print("".. comboTrack1.Name .. " " .. comboTrack2.Name) -- tells the game the anims work
	tool.Activated:Connect(function()
		if canSwing == true and swingDB ~= true and isSwinging ~= true then
			-- Attacking
			swingDB = true -- makes the player unable to repeat swinging
			isSwinging = true
			if combo == 1 then
				comboTrack1:Play()
				handle.Swing1:Play()
				handle.Trail.Enabled = true
				--print("first combo")
				wait(comboTrack1.Length)
				combo = 2
				handle.Trail.Enabled = false
				swingDB = false
			elseif combo == 2 then
				comboTrack2:Play()
				handle.Swing2:Play()
				handle.Trail.Enabled = true
				--print("second combo")
				wait(comboTrack2.Length)
				combo = 1 -- resets the combo back to one so you can start over.
				handle.Trail.Enabled = false
				swingDB = false
			end
			isSwinging = false
		end
	end)
	local function onHit(hit)
		if hit and hit.Parent:FindFirstChildWhichIsA('Humanoid') and hit.Parent:FindFirstChildWhichIsA('Humanoid').Name ~= "Humanoid" and isSwinging == true and canDamage == true and isEquipped then
			canDamage = false
			print("Got hit")
			delay(.95, function()
				canDamage = true
			end)
		end
	end
	tool.Weapon.Touched:Connect(function(hit)
		onHit(hit)
	end)
	tool.Unequipped:Connect(function()
		for i, v in pairs(human.Animator:GetPlayingAnimationTracks()) do
			if v.Name == "Swing1" or v.Name == "Swing2" or v.Name == 'MeleeIdle' or v.Name == "Unequip" or v.Name == "MeleeEquip" then
				v:Stop(.5)
			end
		end
		--table.clear(animations)
		isEquipped = false
	end)
end)