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

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
