local Y={}Y.cr=coroutine.resume Y.cc=coroutine.create Y.crcc=function(Y)return coroutine.resume(coroutine.create(Y))end Y.FindFirstChildWithAttribute=function(Y,b,e,s)if type(Y)=="\116\097\098\108\101"then Y=b b=e end for Y,C in pairs(Y:GetChildren())do if C:GetAttribute(b)then if e==true then return C:GetAttribute(b)else if s and C:GetAttribute(b)==s then return C else return C end end end end return nil end Y.FindFirstChildWithPropertyValue=function(Y,b,e)for Y,s in pairs(Y:GetChildren())do if s[b]and s[b]==e then return s end end return nil end Y.GlobalTrackSwitch=function(b,e)local s=Y.FindFirstChildWithPropertyValue(workspace.GlobalSounds,"\080\108\097\121\105\110\103",true)local C=workspace.GlobalSounds:FindFirstChild(b)local V=C.Volume if C.Playing==true then return else C:Play()C.Volume=0 end local j=TweenService:Create(s,TweenInfo.new(e),{Volume=0})local h=TweenService:Create(C,TweenInfo.new(e),{Volume=V})j:Play()h:Play()Y.crcc(function()task.wait(e)s:Stop()end)end Y.TextTransition=function(Y,b,e,s,C)local V=Y[b]local j=string.len(V)local h=string.len(e)local R=s or 1 local u=C or"\067\111\108\108\097\112\115\101"if u=="\067\111\108\108\097\112\115\101"then for e=2,j/2,1 do Y[b]=string.sub(V,e,j-(e-1))task.wait((R/2)*.25)end Y[b]=" "task.wait((R/2)*.25)for s=h/2,0,-1 do Y[b]=string.sub(e,s,h-(s-1))task.wait((R/2)*.25)end elseif u=="\083\099\114\097\109\098\108\101"then end end return Y



local Utilities = {}

Utilities.cr = coroutine.resume
Utilities.cc = coroutine.create
Utilities.crcc = function(func)
	return coroutine.resume(coroutine.create(func))
end

Utilities.FindFirstChildWithAttribute = function(Parent, AttributeName, ReturnAttributeValue, Value)
	
	if type(Parent) == "table" then
		Parent = AttributeName
		AttributeName = ReturnAttributeValue
	end
	
	for _, Child in pairs(Parent:GetChildren()) do
		if Child:GetAttribute(AttributeName) then
			if ReturnAttributeValue == true then
				return Child:GetAttribute(AttributeName)
			else
				if Value and Child:GetAttribute(AttributeName) == Value then
					return Child
				else
					return Child
				end
			end
		end
	end

	return nil
end

Utilities.FindFirstChildWithPropertyValue = function(Parent, Property, Value)
	for _, Child in pairs(Parent:GetChildren()) do
		if Child[Property] and Child[Property] == Value then
			return Child
		end
	end

	return nil
end

Utilities.GlobalTrackSwitch = function(NewTrack, FadeTime)

	-- Find what Sound in workspace.GlobalSounds is playing, tween fade it out and tween fade in NewTrack

	-- Find the current track
	local CurrentTrack = Utilities.FindFirstChildWithPropertyValue(workspace.GlobalSounds, "Playing", true)
	local NewTrack = workspace.GlobalSounds:FindFirstChild(NewTrack)
	local NewTrackInitVol = NewTrack.Volume

	--print(CurrentTrack)

	-- If the new track is already playing, return
	if NewTrack.Playing == true then
		return
	else
		NewTrack:Play()
		NewTrack.Volume = 0
	end

	-- Fade out current track and fade in new track
	local CurrentTrackFade = TweenService:Create(CurrentTrack, TweenInfo.new(FadeTime), {Volume = 0})
	local NewTrackFade = TweenService:Create(NewTrack, TweenInfo.new(FadeTime), {Volume = NewTrackInitVol})
	CurrentTrackFade:Play()
	NewTrackFade:Play()

	Utilities.crcc(function()
		task.wait(FadeTime)
		CurrentTrack:Stop()
	end)

end

Utilities.TextTransition = function(Object, TextProperty, EndText, Speed, TransitionType)
	
	local StartText = Object[TextProperty]
	local StartTextLength = string.len(StartText)
	local EndTextLength = string.len(EndText)

	local Speed = Speed or 1
	local TransitionType = TransitionType or "Collapse"

	if TransitionType == "Collapse" then
		-- Take one letter from beginning and end until no letters are left, then do the opposite with EndText
		
		for i=2, StartTextLength/2 do  -- Collapse
			Object[TextProperty] = string.sub(StartText, i, StartTextLength-(i-1))
			task.wait(Speed/2*.25)
		end
		
		Object[TextProperty] = " "
		task.wait(Speed/2*.25)

		for  i=EndTextLength/2, 0, -1 do  -- Expand from middle
			Object[TextProperty] =  string.sub(EndText, i, EndTextLength-(i-1))
			task.wait(Speed/2*.25)
		end

	elseif TransitionType == "Scramble" then
		-- Randomly swap out letters from StartText to EndText

	end
end

return Utilities
