Animate.Rotate=require(script:WaitForChild("\082\111\116\097\116\101"))Animate.Animations={}Animate.Last={}Animate.Humanoid=nil function Animate.GetHumanoid()if not Animate.Humanoid then repeat wait()until Animate.Humanoid and Animate.Humanoid:IsDescendantOf(workspace)end return Animate.Humanoid end function Animate.GetNextNumber(P,F)local t=Animate.Animations[P]local s=t and t[F]or nil if s then local t=Animate.Last[P][F]or 1 local U=t+1<=#s and t+1 or 1 return U end return 1 end function Animate.Stop(P,F)if P then if F then local t=Animate.Animations[P][F][Animate.Last[P][F]]if t then t:Stop()end else if Animate.Animations[P]then for P,F in pairs(Animate.Animations[P])do for P,F in pairs(F)do if F then F:Stop()end end end end end end end function Animate.Play(P,F,t,s)if P and F then local U=Animate.Animations[P]if U then local Y=U[F]if Y then local U=Animate.Last[F]t=t or Animate.GetNextNumber(P,F)Animate.Last[P][F]=t Y[t]:Play()Y[t]:AdjustSpeed(s or 1.0)end end end end function Animate.Load(P,F,t,s)if P and(F and t)then local U=Animate.GetHumanoid()local Y=Instance.new("\065\110\105\109\097\116\105\111\110")Y.AnimationId=t local R=U:LoadAnimation(Y)Animate.Animations[P]=Animate.Animations[P]or{}Animate.Animations[P][F]=Animate.Animations[P][F]or{}if not s then table.insert(Animate.Animations[P][F],R)else for s=1,#Animate.Animations[P][F],1 do local U=Animate.Animations[P][F][s]if U.Animation.AnimationId==t then Animate.Animations[P][F][s]=R end end end Animate.Last[P]={[F]=1}return R end end function Animate.Unload(P,F,t)local s=Animate.Animations[P]if not F and s then for P,F in pairs(s)do s[P]={}end else local P=s and s[F]or nil if P then if t then for F=1,#P,1 do if P[F]==t then table.remove(P,F)end end else s[F]={}end end end end function Animate.GetTrack(P,F,t)if Animate.Animations[P]and Animate.Animations[P][F]then for P,F in pairs(Animate.Animations[P][F])do if F.Animation.AnimationId==t then return F end end end end function Animate.Reload()for P,F in pairs(Animate.Animations)do for F,t in pairs(F)do for t,s in pairs(t)do Animate.Load(P,F,s.Animation.AnimationId,true)end end end end return Animate

	Animate.Rotate = require(script:WaitForChild("Rotate"))
	Animate.Animations = {
		--[[ Tool = {
			Idle = animation_track;
			Action = {
				animation_track;
				animation_track;
				animation_track;	
			}
		}]]--
	}
	
	Animate.Last = {}
	
	Animate.Humanoid = nil; -- Player requires this module and sets this.
	
	function Animate.GetHumanoid()
		if not Animate.Humanoid then
			repeat wait() until Animate.Humanoid and Animate.Humanoid:IsDescendantOf(workspace)
		end
		return Animate.Humanoid
	end
	
	
	function Animate.GetNextNumber(category,state)
		local category_list = Animate.Animations[category]
		local state_list = category_list and category_list[state] or nil
		if state_list then
			local state_last_number = Animate.Last[category][state] or 1
			local next_number = (state_last_number + 1 <= #state_list) and state_last_number+1 or 1
			return next_number
		end
		return 1
	end
	
	-- stops the animation from the current category of the given state.
	-- if no state is given, stop all
	function Animate.Stop(category,state)
		if category then
			if state then
				local track = Animate.Animations[category][state][Animate.Last[category][state]]
				if track then
					track:Stop()
				end
			else
				if Animate.Animations[category]then
					for state,tracks in pairs(Animate.Animations[category]) do
						for _,track in pairs(tracks) do
							if track then
								track:Stop()
							end
						end
					end
				end
			end
		end
	end

	function Animate.Play(category,state,number,at_speed)
		if category and state then
			local category_list = Animate.Animations[category]
			if category_list then
				local state_list = category_list[state]
				if state_list then
					local state_last_number = Animate.Last[state]
					number = number or Animate.GetNextNumber(category,state)
					Animate.Last[category][state] = number
					state_list[number]:Play()
					state_list[number]:AdjustSpeed(at_speed or 1.0)
				end
			end
		end
	end
	
	-- creates a new animation track, and saves it to Animate.Animations[category][state]
	function Animate.Load(category,state,id,replace_slot)
		if category and state and id then
			local humanoid = Animate.GetHumanoid()
			local animation = Instance.new("Animation")
			animation.AnimationId = id
			local track = humanoid:LoadAnimation(animation)
			Animate.Animations[category] = Animate.Animations[category] or {}
			Animate.Animations[category][state] = Animate.Animations[category][state] or {}
			if not replace_slot then
				table.insert(Animate.Animations[category][state], track)
			else
				for i=1,#Animate.Animations[category][state] do -- loop thru and replace the animation track with the new one (called from reload)
					local t = Animate.Animations[category][state][i]
					if t.Animation.AnimationId == id then
						Animate.Animations[category][state][i] = track; 
					end
				end
			end
			Animate.Last[category] = {
				[state] = 1;
			}
			return track
		end
	end
	
	-- removes an id from the state list.
	-- if no state supplied, all states are unloaded (set to {})
	-- if no id supplied, sets the state list to {};
	function Animate.Unload(category,state,id)
		local category_list = Animate.Animations[category]
		if not state and category_list then
			for state,list in pairs(category_list) do
				category_list[state] = {}
			end
		else
			local state_list = category_list and category_list[state] or nil
			if state_list then
				if id then
					for i=1,#state_list do
						if state_list[i] == id then
							table.remove(state_list,i)
						end
					end
				else
					category_list[state] = {};
				end
			end
		end
	end
	
	function Animate.GetTrack(category, state, id)
		if Animate.Animations[category] and Animate.Animations[category][state] then
			for _, track in pairs(Animate.Animations[category][state]) do
				if track.Animation.AnimationId == id then
					return track
				end
			end
		end
	end
	
	-- reloads all the current anims
	function Animate.Reload()
		for category, states in pairs(Animate.Animations) do
			for state, tracks in pairs(states) do
				for track_num, track in pairs(tracks) do
					Animate.Load(category, state, track.Animation.AnimationId, true)
				end
			end
		end
	end


return Animate