local function G(G,t)local q=G:WaitForChild("\083\116\105\099\107")local U=G:WaitForChild("\066\117\116\116\111\110")local O=false local function j(U)local O=U.X-G.AbsolutePosition.X local j=U.Y-G.AbsolutePosition.Y O=O<0 and 0 or O>G.AbsoluteSize.X and G.AbsoluteSize.X or O j=j<0 and 0 or j>G.AbsoluteSize.Y and G.AbsoluteSize.Y or j local c=(O/G.AbsoluteSize.X-.5)*2 local L=-(j/G.AbsoluteSize.Y-.5)*2 q.Position=UDim2.new(0,O,0,j)t(c,L)end local function c(G)O=true j(G)U.Size=UDim2.new(10,0,10,0)end local function L(G)O=false q:TweenPosition(UDim2.new(.5,0,.5,0),"\079\117\116","\081\117\105\110\116",.15,true)U.Size=UDim2.new(1,0,1,0)t(0,0)end U.InputChanged:Connect(function(G)if O and G.UserInputType==Enum.UserInputType.Touch then j(G.Position)end end)U.MouseButton1Down:Connect(function(G,t)c(Vector3.new(G,t,0))end)U.InputEnded:Connect(function(G)if G.UserInputType==Enum.UserInputType.Touch then L(G.Position)end end)end
-- Set up an on-screen thumbstick control:
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()
