function Thumbstick.Enable(S)Enabled=true ThumbstickFrame.Visible=true local e=MasterControl:GetHumanoid()enableAutoJump(e)end function Thumbstick.Disable(S)Enabled=false if RevertAutoJumpEnabledToFalse then local S=MasterControl:GetHumanoid()if S then S.AutoJumpEnabled=false end end ThumbstickFrame.Visible=false OnMoveTouchEnded()end function Thumbstick.GetInputObject(S)return MoveTouchObject end function Thumbstick.Create(e,S)if ThumbstickFrame then ThumbstickFrame:Destroy()ThumbstickFrame=nil if OnTouchMovedCn then OnTouchMovedCn:disconnect()OnTouchMovedCn=nil end if OnTouchEndedCn then OnTouchEndedCn:disconnect()OnTouchEndedCn=nil end if OnRenderSteppedCn then OnRenderSteppedCn:disconnect()OnRenderSteppedCn=nil end if TouchActivateCn then TouchActivateCn:disconnect()TouchActivateCn=nil end end local z=45 local l=20 local E=10 local s=E+4 local B=2 local f=50 local m=S.AbsoluteSize local y=math.min(m.x,m.y)>500 if y then z=z*2 l=l*2 E=E*2 s=s*2 B=B*2 f=f*2 end local H=Color3.fromRGB(255,255,255)local function g(S)if S then ThumbstickFrame.Size=UDim2.new(1,0,.4,0)ThumbstickFrame.Position=UDim2.new(0,0,.6,0)GestureArea.Size=UDim2.new(1,0,.6,0)GestureArea.Position=UDim2.new(0,0,0,0)else ThumbstickFrame.Size=UDim2.new(.4,0,.66666666666667,0)ThumbstickFrame.Position=UDim2.new(0,0,.33333333333333,0)GestureArea.Size=UDim2.new(1,0,1,0)GestureArea.Position=UDim2.new(0,0,0,0)end end GestureArea=Instance.new("\070\114\097\109\101")GestureArea.Name="\071\101\115\116\117\114\101\065\114\101\097"GestureArea.Active=false GestureArea.Visible=true GestureArea.BackgroundTransparency=1 GestureArea.BackgroundColor3=Color3.fromRGB(0,0,0)ThumbstickFrame=Instance.new("\070\114\097\109\101")ThumbstickFrame.Name="\068\121\110\097\109\105\099\084\104\117\109\098\115\116\105\099\107\070\114\097\109\101"ThumbstickFrame.Active=false ThumbstickFrame.Visible=false ThumbstickFrame.BackgroundTransparency=1.0 ThumbstickFrame.BackgroundColor3=Color3.fromRGB(0,0,0)g()StartImage=Instance.new("\073\109\097\103\101\076\097\098\101\108")StartImage.Name="\084\104\117\109\098\115\116\105\099\107\083\116\097\114\116"StartImage.Visible=true StartImage.BackgroundTransparency=1 StartImage.Image=TOUCH_CONTROLS_SHEET StartImage.ImageRectOffset=Vector2.new(1,1)StartImage.ImageRectSize=Vector2.new(144,144)StartImage.ImageColor3=Color3.new(0,0,0)StartImage.AnchorPoint=Vector2.new(.5,.5)StartImage.Position=UDim2.new(0,l*3.3,1,-l*2.8)StartImage.Size=UDim2.new(0,l*3.7,0,l*3.7)StartImage.ZIndex=10 StartImage.Parent=ThumbstickFrame EndImage=Instance.new("\073\109\097\103\101\076\097\098\101\108")EndImage.Name="\084\104\117\109\098\115\116\105\099\107\069\110\100"EndImage.Visible=true EndImage.BackgroundTransparency=1 EndImage.Image=TOUCH_CONTROLS_SHEET EndImage.ImageRectOffset=Vector2.new(1,1)EndImage.ImageRectSize=Vector2.new(144,144)EndImage.AnchorPoint=Vector2.new(.5,.5)EndImage.Position=StartImage.Position EndImage.Size=UDim2.new(0,z*.8,0,z*.8)EndImage.ZIndex=10 EndImage.Parent=ThumbstickFrame for S=1,NUM_MIDDLE_IMAGES,1 do MiddleImages[S]=Instance.new("\073\109\097\103\101\076\097\098\101\108")MiddleImages[S].Name="\084\104\117\109\098\115\116\105\099\107\077\105\100\100\108\101"MiddleImages[S].Visible=false MiddleImages[S].BackgroundTransparency=1 MiddleImages[S].Image=TOUCH_CONTROLS_SHEET MiddleImages[S].ImageRectOffset=Vector2.new(1,1)MiddleImages[S].ImageRectSize=Vector2.new(144,144)MiddleImages[S].ImageTransparency=MIDDLE_TRANSPARENCIES[S]MiddleImages[S].AnchorPoint=Vector2.new(.5,.5)MiddleImages[S].ZIndex=9 MiddleImages[S].Parent=ThumbstickFrame end local k=nil local function t()if k then k:Disconnect()k=nil end local S=workspace.CurrentCamera if S then local function e()local e=S.ViewportSize local z=e.X<e.Y g(z)end k=(S:GetPropertyChangedSignal("\086\105\101\119\112\111\114\116\083\105\122\101")):Connect(e)e()end end;(workspace:GetPropertyChangedSignal("\067\117\114\114\101\110\116\067\097\109\101\114\097")):Connect(t)if workspace.CurrentCamera then t()end MoveTouchObject=nil local F=nil local O=nil local T,q,M=nil,nil,{}local function W(S)if not S and MoveTouchObject then return end if IsFirstTouch then return end if T then T:Cancel()end if q then q:Cancel()end for S=1,#MiddleImages,1 do if M[S]then M[S]:Cancel()end end if S then T=TweenService:Create(StartImage,ThumbstickFadeTweenInfo,{ImageTransparency=0})T:Play()q=TweenService:Create(EndImage,ThumbstickFadeTweenInfo,{ImageTransparency=.2})q:Play()for S=1,#MiddleImages,1 do M[S]=TweenService:Create(MiddleImages[S],ThumbstickFadeTweenInfo,{ImageTransparency=MIDDLE_TRANSPARENCIES[S]})M[S]:Play()end else T=TweenService:Create(StartImage,ThumbstickFadeTweenInfo,{ImageTransparency=1})T:Play()q=TweenService:Create(EndImage,ThumbstickFadeTweenInfo,{ImageTransparency=1})q:Play()for S=1,#MiddleImages,1 do M[S]=TweenService:Create(MiddleImages[S],ThumbstickFadeTweenInfo,{ImageTransparency=1})M[S]:Play()end end end local function V(S,e)FadeInAndOutHalfDuration=S*.5 FadeInAndOutBalance=e TweenInAlphaStart=tick()end local function P(S)MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=S local e=currentMoveVector.magnitude if e<B then currentMoveVector=Vector3.new()else currentMoveVector=currentMoveVector.unit*(1-math.max(0,(f-currentMoveVector.magnitude)/f))currentMoveVector=Vector3.new(currentMoveVector.x,0,currentMoveVector.y)end MasterControl:AddToPlayerMovement(currentMoveVector)end local function x(S,e)local B=z/2+E local f=e-S local m=(f.magnitude-l/2)-E local y=f.unit local H=s*NUM_MIDDLE_IMAGES local g=s if H<m then g=m/NUM_MIDDLE_IMAGES end for S=1,NUM_MIDDLE_IMAGES,1 do local z=MiddleImages[S]local l=B+g*(S-2)local s=B+g*(S-1)if l<m then local S=e-y*s local l=math.clamp(1-(s-m)/g,0,1)z.Visible=true z.Position=UDim2.new(0,S.X,0,S.Y)z.Size=UDim2.new(0,E*l,0,E*l)else z.Visible=false end end end local function d(S)local e=Vector2.new(O.X,O.Y)-ThumbstickFrame.AbsolutePosition local z=Vector2.new(S.X,S.Y)-ThumbstickFrame.AbsolutePosition local l=z-e local E=l.magnitude local s=ThumbstickFrame.AbsoluteSize.X E=math.min(E,s)l=l*E EndImage.Position=UDim2.new(0,z.X,0,z.Y)x(e,z)end ThumbstickFrame.InputBegan:connect(function(S)if S.UserInputType~=Enum.UserInputType.Touch or S.UserInputState~=Enum.UserInputState.Begin then return end if MoveTouchObject then return end if IsFirstTouch then IsFirstTouch=false local S=TweenInfo.new(.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0);(TweenService:Create(StartImage,S,{Size=UDim2.new(0,0,0,0)})):Play();(TweenService:Create(EndImage,S,{Size=UDim2.new(0,z,0,z);ImageColor3=Color3.new(0,0,0)})):Play()end MoveTouchObject=S F=tick()O=S.Position local e=Vector2.new(S.Position.X-ThumbstickFrame.AbsolutePosition.X,S.Position.Y-ThumbstickFrame.AbsolutePosition.Y)StartImage.Visible=true StartImage.Position=UDim2.new(0,e.X,0,e.Y)EndImage.Visible=true EndImage.Position=StartImage.Position W(true)d(S.Position)if FadeInAndOutBackground then local S=LocalPlayer:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")local e=false if S then if S.CurrentScreenOrientation==Enum.ScreenOrientation.LandscapeLeft or S.CurrentScreenOrientation==Enum.ScreenOrientation.LandscapeRight then e=HasFadedBackgroundInLandscape HasFadedBackgroundInLandscape=true elseif S.CurrentScreenOrientation==Enum.ScreenOrientation.Portrait then e=HasFadedBackgroundInPortrait HasFadedBackgroundInPortrait=true end end if not e then FadeInAndOutHalfDuration=FADE_IN_OUT_HALF_DURATION_DEFAULT FadeInAndOutBalance=FADE_IN_OUT_BALANCE_DEFAULT TweenInAlphaStart=tick()end end end)OnTouchMovedCn=UserInputService.TouchMoved:connect(function(S,e)if S==MoveTouchObject then local e=Vector2.new(S.Position.x-O.x,S.Position.y-O.y)if math.abs(e.x)>0 or math.abs(e.y)>0 then P(e)d(S.Position)end end end)OnMoveTouchEnded=function(S)if S then local e=Vector2.new(S.Position.x-O.x,S.Position.y-O.y)end MoveTouchObject=nil W(false)MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)end OnRenderSteppedCn=RunService.RenderStepped:Connect(function(S)if TweenInAlphaStart~=nil then local S=tick()-TweenInAlphaStart local e=(FadeInAndOutHalfDuration*2)*FadeInAndOutBalance ThumbstickFrame.BackgroundTransparency=1-FadeInAndOutMaxAlpha*math.min(S/e,1)if S>e then TweenOutAlphaStart=tick()TweenInAlphaStart=nil end elseif TweenOutAlphaStart~=nil then local S=tick()-TweenOutAlphaStart local e=FadeInAndOutHalfDuration*2-(FadeInAndOutHalfDuration*2)*FadeInAndOutBalance ThumbstickFrame.BackgroundTransparency=(1-FadeInAndOutMaxAlpha)+FadeInAndOutMaxAlpha*math.min(S/e,1)if S>e then TweenOutAlphaStart=nil end end end)OnTouchEndedCn=UserInputService.TouchEnded:connect(function(S,e)if S==MoveTouchObject then OnMoveTouchEnded(S)end end)GuiService.MenuOpened:connect(function()if MoveTouchObject then OnMoveTouchEnded(nil)end end)local X=LocalPlayer:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")while not X do LocalPlayer.ChildAdded:wait()X=LocalPlayer:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")end local Z=nil local j=X.CurrentScreenOrientation==Enum.ScreenOrientation.LandscapeLeft or X.CurrentScreenOrientation==Enum.ScreenOrientation.LandscapeRight local function G()FadeInAndOutHalfDuration=2.5 FadeInAndOutBalance=.05 TweenInAlphaStart=tick()end Z=X.Changed:connect(function(S)if S=="\067\117\114\114\101\110\116\083\099\114\101\101\110\079\114\105\101\110\116\097\116\105\111\110"then if j and X.CurrentScreenOrientation==Enum.ScreenOrientation.Portrait or not j and X.CurrentScreenOrientation~=Enum.ScreenOrientation.Portrait then Z:disconnect()G()if j then HasFadedBackgroundInPortrait=true else HasFadedBackgroundInLandscape=true end end end end)GestureArea.Parent=S.Parent ThumbstickFrame.Parent=S spawn(function()if game:IsLoaded()then G()else game.Loaded:wait()G()end end)end return Thumbstick
--
function Thumbstick:Enable()
	Enabled = true
	ThumbstickFrame.Visible = true
	local humanoid = MasterControl:GetHumanoid()
	enableAutoJump(humanoid)
end

function Thumbstick:Disable()
	Enabled = false
	if RevertAutoJumpEnabledToFalse then
		local humanoid = MasterControl:GetHumanoid()
		if humanoid then
			humanoid.AutoJumpEnabled = false
		end
	end
	ThumbstickFrame.Visible = false
	OnMoveTouchEnded()
end

function Thumbstick:GetInputObject()
    return MoveTouchObject
end

function Thumbstick:Create(parentFrame)
	if ThumbstickFrame then
		ThumbstickFrame:Destroy()
		ThumbstickFrame = nil
		if OnTouchMovedCn then
			OnTouchMovedCn:disconnect()
			OnTouchMovedCn = nil
		end
		if OnTouchEndedCn then
			OnTouchEndedCn:disconnect()
			OnTouchEndedCn = nil
		end
		if OnRenderSteppedCn then
			OnRenderSteppedCn:disconnect()
			OnRenderSteppedCn = nil
		end
		if TouchActivateCn then
			TouchActivateCn:disconnect()
			TouchActivateCn = nil
		end
	end
	
	local ThumbstickSize = 45
	local ThumbstickRingSize = 20
	local MiddleSize = 10
	local MiddleSpacing = MiddleSize + 4
	local RadiusOfDeadZone = 2
	local RadiusOfMaxSpeed = 50
	
	local screenSize = parentFrame.AbsoluteSize
	local isBigScreen = math.min(screenSize.x, screenSize.y) > 500
	if isBigScreen then
		ThumbstickSize = ThumbstickSize * 2
		ThumbstickRingSize = ThumbstickRingSize * 2
		MiddleSize = MiddleSize * 2
		MiddleSpacing = MiddleSpacing * 2
		RadiusOfDeadZone = RadiusOfDeadZone * 2
		RadiusOfMaxSpeed = RadiusOfMaxSpeed * 2
	end
	
	local color = Color3.fromRGB(255, 255, 255)
	
	local function layoutThumbstickFrame(portraitMode)
		if portraitMode then
			ThumbstickFrame.Size = UDim2.new(1, 0, 0.4, 0)
			ThumbstickFrame.Position = UDim2.new(0, 0, 0.6, 0)
			GestureArea.Size = UDim2.new(1, 0, 0.6, 0)
			GestureArea.Position = UDim2.new(0, 0, 0, 0)
		else
			ThumbstickFrame.Size = UDim2.new(0.4, 0, 2/3, 0)
			ThumbstickFrame.Position = UDim2.new(0, 0, 1/3, 0)
			GestureArea.Size = UDim2.new(1, 0, 1, 0)
			GestureArea.Position = UDim2.new(0, 0, 0, 0)
		end
	end

	GestureArea = Instance.new("Frame")
	GestureArea.Name = "GestureArea"
	GestureArea.Active = false
	GestureArea.Visible = true
	GestureArea.BackgroundTransparency = 1
	GestureArea.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
		
	ThumbstickFrame = Instance.new('Frame')
	ThumbstickFrame.Name = "DynamicThumbstickFrame"
	ThumbstickFrame.Active = false
	ThumbstickFrame.Visible = false
	ThumbstickFrame.BackgroundTransparency = 1.0
	ThumbstickFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
	layoutThumbstickFrame()

	StartImage = Instance.new("ImageLabel")
	StartImage.Name = "ThumbstickStart"
	StartImage.Visible = true
	StartImage.BackgroundTransparency = 1
	
	StartImage.Image = TOUCH_CONTROLS_SHEET
	StartImage.ImageRectOffset = Vector2.new(1,1)
	StartImage.ImageRectSize = Vector2.new(144, 144)
	StartImage.ImageColor3 = Color3.new(0, 0, 0)
	StartImage.AnchorPoint = Vector2.new(0.5, 0.5)
	StartImage.Position = UDim2.new(0, ThumbstickRingSize * 3.3, 1, -ThumbstickRingSize * 2.8)
	StartImage.Size = UDim2.new(0, ThumbstickRingSize * 3.7, 0, ThumbstickRingSize * 3.7)
	StartImage.ZIndex = 10
	StartImage.Parent = ThumbstickFrame
	
	EndImage = Instance.new("ImageLabel")
	EndImage.Name = "ThumbstickEnd"
	EndImage.Visible = true
	EndImage.BackgroundTransparency = 1
	EndImage.Image = TOUCH_CONTROLS_SHEET
	EndImage.ImageRectOffset = Vector2.new(1,1)
	EndImage.ImageRectSize =  Vector2.new(144, 144)
	EndImage.AnchorPoint = Vector2.new(0.5, 0.5)
	EndImage.Position = StartImage.Position
	EndImage.Size = UDim2.new(0, ThumbstickSize * 0.8, 0, ThumbstickSize * 0.8)
	EndImage.ZIndex = 10
	EndImage.Parent = ThumbstickFrame
	
	for i = 1, NUM_MIDDLE_IMAGES do
		MiddleImages[i] = Instance.new("ImageLabel")
		MiddleImages[i].Name = "ThumbstickMiddle"
		MiddleImages[i].Visible = false
		MiddleImages[i].BackgroundTransparency = 1
		MiddleImages[i].Image = TOUCH_CONTROLS_SHEET
		MiddleImages[i].ImageRectOffset = Vector2.new(1,1)
		MiddleImages[i].ImageRectSize = Vector2.new(144, 144)
		MiddleImages[i].ImageTransparency = MIDDLE_TRANSPARENCIES[i]
		MiddleImages[i].AnchorPoint = Vector2.new(0.5, 0.5)
		MiddleImages[i].ZIndex = 9
		MiddleImages[i].Parent = ThumbstickFrame
	end

	local CameraChangedConn = nil
	local function onCurrentCameraChanged()
		if CameraChangedConn then
			CameraChangedConn:Disconnect()
			CameraChangedConn = nil
		end
		local newCamera = workspace.CurrentCamera
		if newCamera then
			local function onViewportSizeChanged()
				local size = newCamera.ViewportSize
				local portraitMode = size.X < size.Y
				layoutThumbstickFrame(portraitMode)
			end
			CameraChangedConn = newCamera:GetPropertyChangedSignal("ViewportSize"):Connect(onViewportSizeChanged)
			onViewportSizeChanged()
		end
	end
	workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(onCurrentCameraChanged)
	if workspace.CurrentCamera then
		onCurrentCameraChanged()
	end
	
	MoveTouchObject = nil
	local MoveTouchStartTime = nil
	local MoveTouchStartPosition = nil

	local startImageFadeTween, endImageFadeTween, middleImageFadeTweens = nil, nil, {}
	local function fadeThumbstick(visible)
		if not visible and MoveTouchObject then
			return
		end
		if IsFirstTouch then return end
		
		if startImageFadeTween then
			startImageFadeTween:Cancel()
		end
		if endImageFadeTween then
			endImageFadeTween:Cancel()
		end
		for i = 1, #MiddleImages do
			if middleImageFadeTweens[i] then
				middleImageFadeTweens[i]:Cancel()
			end
		end

		if visible then
			startImageFadeTween = TweenService:Create(StartImage, ThumbstickFadeTweenInfo, { ImageTransparency = 0 })
			startImageFadeTween:Play()

			endImageFadeTween = TweenService:Create(EndImage, ThumbstickFadeTweenInfo, { ImageTransparency = 0.2 })
			endImageFadeTween:Play()

			for i = 1, #MiddleImages do
				middleImageFadeTweens[i] = TweenService:Create(MiddleImages[i], ThumbstickFadeTweenInfo, { ImageTransparency = MIDDLE_TRANSPARENCIES[i] })
				middleImageFadeTweens[i]:Play()
			end
		else
			startImageFadeTween = TweenService:Create(StartImage, ThumbstickFadeTweenInfo, { ImageTransparency = 1 })
			startImageFadeTween:Play()

			endImageFadeTween = TweenService:Create(EndImage, ThumbstickFadeTweenInfo, { ImageTransparency = 1 })
			endImageFadeTween:Play()

			for i = 1, #MiddleImages do
				middleImageFadeTweens[i] = TweenService:Create(MiddleImages[i], ThumbstickFadeTweenInfo, { ImageTransparency = 1 })
				middleImageFadeTweens[i]:Play()
			end
		end
	end
	local function fadeThumbstickFrame(fadeDuration, fadeRatio)
		FadeInAndOutHalfDuration = fadeDuration * 0.5
		FadeInAndOutBalance = fadeRatio
		TweenInAlphaStart = tick()
	end
		
	local function doMove(direction)
		MasterControl:AddToPlayerMovement(-currentMoveVector)
		
		currentMoveVector = direction
		
		-- Scaled Radial Dead Zone
		local inputAxisMagnitude = currentMoveVector.magnitude
		if inputAxisMagnitude < RadiusOfDeadZone then
			currentMoveVector = Vector3.new()
		else
			currentMoveVector = currentMoveVector.unit*(1 - math.max(0, (RadiusOfMaxSpeed - currentMoveVector.magnitude)/RadiusOfMaxSpeed))
			currentMoveVector = Vector3.new(currentMoveVector.x, 0, currentMoveVector.y)
		end
		
		MasterControl:AddToPlayerMovement(currentMoveVector)
	end
	
	local function layoutMiddleImages(startPos, endPos)
		local startDist = (ThumbstickSize / 2) + MiddleSize
		local vector = endPos - startPos
		local distAvailable = vector.magnitude - (ThumbstickRingSize / 2) - MiddleSize
		local direction = vector.unit

		local distNeeded = MiddleSpacing * NUM_MIDDLE_IMAGES
		local spacing = MiddleSpacing
		
		if distNeeded < distAvailable then
			spacing = distAvailable / NUM_MIDDLE_IMAGES
		end
			
		for i = 1, NUM_MIDDLE_IMAGES do
			local image = MiddleImages[i]
			local distWithout = startDist + (spacing * (i - 2))
			local currentDist = startDist + (spacing * (i - 1))	
				
			if distWithout < distAvailable then
				local pos = endPos - direction * currentDist
				local exposedFraction = math.clamp(1 - ((currentDist - distAvailable) / spacing), 0, 1)
				
				image.Visible = true
				image.Position = UDim2.new(0, pos.X, 0, pos.Y)
				image.Size = UDim2.new(0, MiddleSize * exposedFraction, 0, MiddleSize * exposedFraction)
			else
				image.Visible = false
			end
		end
	end
	
	local function moveStick(pos)
		local startPos = Vector2.new(MoveTouchStartPosition.X, MoveTouchStartPosition.Y) - ThumbstickFrame.AbsolutePosition
		local endPos = Vector2.new(pos.X, pos.Y) - ThumbstickFrame.AbsolutePosition
		local relativePosition = endPos - startPos
		local length = relativePosition.magnitude
		local maxLength = ThumbstickFrame.AbsoluteSize.X
		
		length = math.min(length, maxLength)
		relativePosition = relativePosition*length
		
		EndImage.Position = UDim2.new(0, endPos.X, 0, endPos.Y)
		
		layoutMiddleImages(startPos, endPos)
	end
	
	-- input connections
	ThumbstickFrame.InputBegan:connect(function(inputObject)
		if inputObject.UserInputType ~= Enum.UserInputType.Touch or inputObject.UserInputState ~= Enum.UserInputState.Begin then
			return
		end
		if MoveTouchObject then
			return
		end
		
		if IsFirstTouch then
			IsFirstTouch = false
			local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out,0,false,0)
			TweenService:Create(StartImage, tweenInfo, {Size = UDim2.new(0, 0, 0, 0)}):Play()
			TweenService:Create(EndImage, tweenInfo, {Size = UDim2.new(0, ThumbstickSize, 0, ThumbstickSize), ImageColor3 = Color3.new(0,0,0)}):Play()
		end

		MoveTouchObject = inputObject
		MoveTouchStartTime = tick()
		MoveTouchStartPosition = inputObject.Position
		local startPosVec2 = Vector2.new(inputObject.Position.X - ThumbstickFrame.AbsolutePosition.X, inputObject.Position.Y - ThumbstickFrame.AbsolutePosition.Y)

		StartImage.Visible = true
		StartImage.Position = UDim2.new(0, startPosVec2.X, 0, startPosVec2.Y)
		EndImage.Visible = true
		EndImage.Position = StartImage.Position
		
		fadeThumbstick(true)
		moveStick(inputObject.Position)
		
		if FadeInAndOutBackground then
			local playerGui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
			local hasFadedBackgroundInOrientation = false

			-- only fade in/out the background once per orientation
			if playerGui then
				if playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.LandscapeLeft or 
					playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.LandscapeRight then
						hasFadedBackgroundInOrientation = HasFadedBackgroundInLandscape
						HasFadedBackgroundInLandscape = true
				elseif playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.Portrait then
						hasFadedBackgroundInOrientation = HasFadedBackgroundInPortrait
						HasFadedBackgroundInPortrait = true
				end
			end

			if not hasFadedBackgroundInOrientation then
				FadeInAndOutHalfDuration = FADE_IN_OUT_HALF_DURATION_DEFAULT
				FadeInAndOutBalance = FADE_IN_OUT_BALANCE_DEFAULT
				TweenInAlphaStart = tick()
			end
		end
	end)
	
	OnTouchMovedCn = UserInputService.TouchMoved:connect(function(inputObject, isProcessed)
		if inputObject == MoveTouchObject then
			
			local direction = Vector2.new(inputObject.Position.x - MoveTouchStartPosition.x, inputObject.Position.y - MoveTouchStartPosition.y)
			if math.abs(direction.x) > 0 or math.abs(direction.y) > 0 then
				doMove(direction)
				moveStick(inputObject.Position)
			end
		end
	end)
	
	OnMoveTouchEnded = function(inputObject)
		if inputObject then
			local direction = Vector2.new(inputObject.Position.x - MoveTouchStartPosition.x, inputObject.Position.y - MoveTouchStartPosition.y)
		end

		MoveTouchObject = nil
		fadeThumbstick(false)
		
		MasterControl:AddToPlayerMovement(-currentMoveVector)
		currentMoveVector = Vector3.new(0,0,0)
	end

	OnRenderSteppedCn = RunService.RenderStepped:Connect(function(step)
		if TweenInAlphaStart ~= nil then
			local delta = tick() - TweenInAlphaStart
			local fadeInTime = (FadeInAndOutHalfDuration * 2 * FadeInAndOutBalance)
			ThumbstickFrame.BackgroundTransparency = 1 - FadeInAndOutMaxAlpha*math.min(delta/fadeInTime, 1)
			if delta > fadeInTime then
				TweenOutAlphaStart = tick()
				TweenInAlphaStart = nil
			end
		elseif TweenOutAlphaStart ~= nil then
			local delta = tick() - TweenOutAlphaStart
			local fadeOutTime = (FadeInAndOutHalfDuration * 2) - (FadeInAndOutHalfDuration * 2 * FadeInAndOutBalance)
			ThumbstickFrame.BackgroundTransparency = 1 - FadeInAndOutMaxAlpha + FadeInAndOutMaxAlpha*math.min(delta/fadeOutTime, 1)
			if delta > fadeOutTime  then
				TweenOutAlphaStart = nil
			end
		end
	end)

	OnTouchEndedCn = UserInputService.TouchEnded:connect(function(inputObject, isProcessed)
		if inputObject == MoveTouchObject then
			OnMoveTouchEnded(inputObject)
		end
	end)
	
	
	GuiService.MenuOpened:connect(function()
		if MoveTouchObject then
			OnMoveTouchEnded(nil)
		end
	end)

	local playerGui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
	while not playerGui do
		LocalPlayer.ChildAdded:wait()
		playerGui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
	end

	local playerGuiChangedConn = nil
	local originalScreenOrientationWasLandscape = playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.LandscapeLeft or
													playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.LandscapeRight

	local function longShowBackground()
		FadeInAndOutHalfDuration = 2.5
		FadeInAndOutBalance = 0.05
		TweenInAlphaStart = tick()
	end

	playerGuiChangedConn = playerGui.Changed:connect(function(prop)
		if prop == "CurrentScreenOrientation" then
			if (originalScreenOrientationWasLandscape and playerGui.CurrentScreenOrientation == Enum.ScreenOrientation.Portrait) or
				(not originalScreenOrientationWasLandscape and playerGui.CurrentScreenOrientation ~= Enum.ScreenOrientation.Portrait) then
					playerGuiChangedConn:disconnect()
					longShowBackground()

					if originalScreenOrientationWasLandscape then
						HasFadedBackgroundInPortrait = true
					else
						HasFadedBackgroundInLandscape = true
					end
			end
		end
	end)
	
	GestureArea.Parent = parentFrame.Parent
	ThumbstickFrame.Parent = parentFrame

	spawn(function()
		if game:IsLoaded() then
			longShowBackground()
		else
			game.Loaded:wait()
			longShowBackground()
		end
	end)
end

return Thumbstick
