-- stops all playin anims

module.stopalltracks = function(hum, fold)
	local AnimationTracks = hum:GetPlayingAnimationTracks()
	local Fold =  fold
	
	local tab = {}
	
	if Fold then
		
		--
		for i, track in pairs (Fold:GetDescendants()) do
			if track:IsA('Animation') then
				tab[track.Name] = track.Name
				--table.insert(tab, track.Name)
			end
		end
		
		--print(tab)
		-- action
		for i, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
			if Fold:FindFirstChild(v.Name) and v.Name == Fold:FindFirstChild(v.Name).Name then
				v:Stop()
				--print("Fold found match: ",v," Table found ->", tab[v])
			end
		end
		
	else
		for i, track in pairs (AnimationTracks) do
			track:Stop()
		end
	end
	

end

module.StopAnim = function(hum,name)
	for i, v in pairs(hum.Animator:GetPlayingAnimationTracks()) do
		if v.Name == name then
			v:Stop()
		end
	end
end

module.LoadTrack = function(hum, anim)
	local animationTrack
	if hum:FindFirstChild("Animator") then
		animationTrack = hum.Animator:LoadAnimation(anim)
	else
		animationTrack = hum:LoadAnimation(anim)
	end
	
	--animationTrack:Play()


	return animationTrack
end

module.play = function(hum, anim)
	local char = hum.Parent
	
	local animationTrack = hum.Animator:LoadAnimation(anim)
	animationTrack:Play()
	
	
	return animationTrack
	
end
