local function q(q)q.button.Parent.BackgroundColor3=released_col if not q.enabled then q.button.Active=false end q.pressed=false q.move_touch_input=nil end function touch_button.Bind(V,O)local d=setmetatable({},{__index=touch_button})d.button=(O:WaitForChild("\073\110\110\101\114")):WaitForChild("\066\117\116\116\111\110")d.button.Active=false d.pressed=false d.move_touch_input=nil d.enabled=false d.input_connections={d.button.InputBegan:Connect(function(q)if d.enabled==false or d.move_touch_input~=nil or q.UserInputType~=Enum.UserInputType.Touch or q.UserInputState~=Enum.UserInputState.Begin then return end d.move_touch_input=q d.button.Parent.BackgroundColor3=pressed_col d.pressed=true end),uis.TouchEnded:Connect(function(O,V)if O==d.move_touch_input then q(d)end end);gui_service.MenuOpened:Connect(function()if d.move_touch_input~=nil then q(d)end end)}return d end function touch_button.Destroy(q)if q.input_connections~=nil then for q,O in pairs(q.input_connections)do O:Disconnect()end q.input_connections=nil end end
--Internal interface
local function OnInputEnded(self)
	--Reset button
	self.button.Parent.BackgroundColor3 = released_col
	if not self.enabled then
		self.button.Active = false
	end

	--Reset input state
	self.pressed = false
	self.move_touch_input = nil
end

function touch_button:Bind(btn)
	--Initialize meta reference
	local self = setmetatable({}, { __index = touch_button })

	--Create button
	self.button = btn:WaitForChild("Inner"):WaitForChild("Button")
	self.button.Active = false

	--Initialize state
	self.pressed = false
	self.move_touch_input = nil
	self.enabled = false

	--Input connections
	self.input_connections = {
		self.button.InputBegan:Connect(function(input)
			--Make sure input is a valid state
			if
				self.enabled == false
				or self.move_touch_input ~= nil
				or input.UserInputType ~= Enum.UserInputType.Touch
				or input.UserInputState ~= Enum.UserInputState.Begin
			then
				return
			end

			--Start holding button
			self.move_touch_input = input
			self.button.Parent.BackgroundColor3 = pressed_col
			self.pressed = true
		end),
		uis.TouchEnded:Connect(function(input, processed)
			if input == self.move_touch_input then
				OnInputEnded(self)
			end
		end),
		gui_service.MenuOpened:Connect(function()
			if self.move_touch_input ~= nil then
				OnInputEnded(self)
			end
		end),
	}

	return self
end
function touch_button:Destroy()
	--Disconnect connections
	if self.input_connections ~= nil then
		for _, v in pairs(self.input_connections) do
			v:Disconnect()
		end
		self.input_connections = nil
	end
end
