function TaskScheduler.CreateScheduler(b,S)local l={}local B={}local J=true local t,d local G local a={}local p local function c()local b=tick()local l=b-G<1 and math.floor(S*(b-G))or S for S=#a,1,-1 do a[S+1]=a[S]>=b-1 and a[S]or nil end a[1]=b if#a>=l then if#B>0 then B[1]()table.remove(B,1)else p()end end end p=function()J=true if t then t:disconnect()t=nil end end local function Y()if J and not t then J=false if not d then G=tick()t=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(c)end end end function l.Pause(S)d=true if t then t:disconnect()t=nil end end function l.Resume(S)if d and not t then d=false J=false G=tick()t=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(c)end end function l.Destroy(S)l:Pause()for S in next,l do l[S]=nil end setmetatable(l,{__index=function()error("\065\116\116\101\109\112\116 \116\111 \117\115\101 \100\101\115\116\114\111\121\101\100 \115\099\104\101\100\117\108\101\114")end;__newindex=function()error("\065\116\116\101\109\112\116 \116\111 \117\115\101 \100\101\115\116\114\111\121\101\100 \115\099\104\101\100\117\108\101\114")end})end function l.QueueTask(b,S)B[#B+1]=S if J then Y()end end G=tick()t=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(c)return l end return TaskScheduler

function TaskScheduler:CreateScheduler(targetFps)
	local scheduler = {}
	local queue = {}
	local sleeping = true
	local event,paused
	
	local start
	local frameUpdateTable = {}
	local sleep--get syntax highlighter to shut up on line 68
	local function onEvent()
		local iterationStart = tick()
		local targetFrameUpdates = (iterationStart-start) < 1 and math.floor(targetFps * (iterationStart-start)) or targetFps
		
		for i=#frameUpdateTable,1,-1 do
			frameUpdateTable[i+1] = (frameUpdateTable[i] >= iterationStart-1) and frameUpdateTable[i] or nil
		end
		frameUpdateTable[1] = iterationStart
		
		if #frameUpdateTable >= targetFrameUpdates then
			if #queue > 0 then
				queue[1]()
				table.remove(queue, 1)
			else
				sleep()
			end
		end
	end
	
	--used for automatically turning off renderstepped loop when there's nothing in the queue
	sleep = function()
		sleeping = true
		if event then
			event:disconnect()
			event = nil
		end
	end
	
	--turns renderstepped loop back on when something is added to the queue and scheduler isn't paused
	local function wake()
		if sleeping and not event then
			sleeping = false
			if not paused then
				start = tick()
				event = game:GetService("RunService").RenderStepped:connect(onEvent)
			end
		end
	end
	
	function scheduler:Pause()
		paused = true
		if event then
			event:disconnect()
			event = nil
		end
	end
	
	function scheduler:Resume()
		if paused and not event then
			paused = false
			sleeping = false
			start = tick()
			event = game:GetService("RunService").RenderStepped:connect(onEvent)
		end
	end
	
	function scheduler:Destroy()
		scheduler:Pause()
		for i in next,scheduler do
			scheduler[i] = nil
		end
		setmetatable(scheduler, {
			__index = function()
				error("Attempt to use destroyed scheduler")
			end;
			__newindex = function()
				error("Attempt to use destroyed scheduler")
			end;
		})
	end
	
	function scheduler:QueueTask(callback)
		queue[#queue+1] = callback 
		if sleeping then
			wake()
		end
	end
	
	start = tick()
	event = game:GetService("RunService").RenderStepped:connect(onEvent)
	
	return scheduler
end

return TaskScheduler
