local function U(U,F)local i=U:WaitForChild("\083\116\105\099\107")local A=U:WaitForChild("\066\117\116\116\111\110")local y=false local function d(A)local y=A.X-U.AbsolutePosition.X local d=A.Y-U.AbsolutePosition.Y y=y<0 and 0 or y>U.AbsoluteSize.X and U.AbsoluteSize.X or y d=d<0 and 0 or d>U.AbsoluteSize.Y and U.AbsoluteSize.Y or d local r=(y/U.AbsoluteSize.X-.5)*2 local S=-(d/U.AbsoluteSize.Y-.5)*2 i.Position=UDim2.new(0,y,0,d)F(r,S)end local function r(U)y=true d(U)A.Size=UDim2.new(10,0,10,0)end local function S(U)y=false i:TweenPosition(UDim2.new(.5,0,.5,0),"\079\117\116","\081\117\105\110\116",.15,true)A.Size=UDim2.new(1,0,1,0)F(0,0)end A.InputChanged:Connect(function(U)if y and U.UserInputType==Enum.UserInputType.Touch then d(U.Position)end end)A.MouseButton1Down:Connect(function(U,F)r(Vector3.new(U,F,0))end)A.InputEnded:Connect(function(U)if U.UserInputType==Enum.UserInputType.Touch then S(U.Position)end end)end

local function ThumbstickSetup(frame, callback)
	local stick = frame:WaitForChild("Stick")
	local btn = frame:WaitForChild("Button")
	
	local btnDown = false
	
	-- Calculate relative position of thumbstick when dragged to screen position "pos":
	local function TouchDragged(pos)
		local x = (pos.X - frame.AbsolutePosition.X)
		local y = (pos.Y - frame.AbsolutePosition.Y)
		x = (x < 0 and 0 or x > frame.AbsoluteSize.X and frame.AbsoluteSize.X or x)
		y = (y < 0 and 0 or y > frame.AbsoluteSize.Y and frame.AbsoluteSize.Y or y)
		local ratioX = ((x / frame.AbsoluteSize.X) - 0.5) * 2
		local ratioY = -((y / frame.AbsoluteSize.Y) - 0.5) * 2
		stick.Position = UDim2.new(0, x, 0, y)
		callback(ratioX, ratioY)
	end
	
	local function StartTouch(pos)
		btnDown = true
		TouchDragged(pos)
		btn.Size = UDim2.new(10, 0, 10, 0)
	end
	
	local function StopTouch(pos)
		btnDown = false
		stick:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), "Out", "Quint", 0.15, true)
		btn.Size = UDim2.new(1, 0, 1, 0)
		callback(0, 0)
	end
	
	btn.InputChanged:Connect(function(input)
		if (btnDown and input.UserInputType == Enum.UserInputType.Touch) then
			TouchDragged(input.Position)
		end
	end)
	
	btn.MouseButton1Down:Connect(function(x, y)
		StartTouch(Vector3.new(x, y, 0))
	end)
	
	btn.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Touch then
			StopTouch(input.Position)
		end
	end)
end -- ThumbstickSetup()