What do you want to achieve? I am trying to disconnect a connection that makes the button move when the player drags it but :Disconnect() is not working.
Help is appreciated
local container = script.Parent
local Icon = require(container.Icon)
local screenGui = player:WaitForChild("PlayerGui"):FindFirstChild("MobileButtons"):WaitForChild("MobileFrame"):WaitForChild("DashButton")
local screenGui2 = player:WaitForChild("PlayerGui"):FindFirstChild("MobileButtons"):WaitForChild("MobileFrame2"):WaitForChild("BlockButton")
local screenGui3 = player:WaitForChild("PlayerGui"):FindFirstChild("MobileButtons"):WaitForChild("MobileFrame3"):WaitForChild("PunchButton")
-- Function to make a UI element draggable
local function makeDraggable(UI)
local Holding = false
local InitialTouchPos
local InitialUIPos
-- Declare MoveConnection outside to be used later
local MoveConnection
-- Function to update the position of the UI element
local function updateUIPosition(input)
if not Holding then return end
local delta = input.Position - InitialTouchPos
UI.Position = UDim2.new(
0, InitialUIPos.X.Offset + delta.X,
0, InitialUIPos.Y.Offset + delta.Y
)
end
-- InputBegan handler
UI.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
Holding = true
InitialTouchPos = input.Position
InitialUIPos = UI.Position
-- Create a connection to track input changes/
MoveConnection = userInputService.InputChanged:Connect(function(changedInput)
if changedInput.UserInputType == Enum.UserInputType.Touch or changedInput.UserInputType == Enum.UserInputType.MouseMovement then
updateUIPosition(changedInput)
end
end)
end
end)
-- InputEnded handler
UI.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
Holding = false
if MoveConnection then
MoveConnection:Disconnect()
MoveConnection = nil
end
end
end)
end
-- Function to disconnect the dragging connections for buttons
local function disconnectDragging(buttons)
for _, button in ipairs(buttons) do
-- Check if MoveConnection exists and disconnect
local moveConnection = screenGui:FindFirstChild("MoveConnection")
local moveConnection2= screenGui2:FindFirstChild("MoveConnection")
local moveConnection3=screenGui3:FindFirstChild("MoveConnection")
if moveConnection then
moveConnection:Disconnect()
moveConnection2:Disconnect()
moveConnection3:Disconnect()
print(moveConnection, moveConnection2, moveConnection3)
end
end
end
Icon.new()
:setLabel("Settings")
:setDropdown({
Icon.new():call(setItemIcon, "Move Mobile Buttons"):select()
:bindEvent("selected", function()
print("Move Mobile Buttons selected")
makeDraggable(screenGui)
makeDraggable(screenGui2)
makeDraggable(screenGui3)
end)
:bindEvent("deselected", function()
disconnectDragging({screenGui, screenGui2, screenGui3}) -- Disconnect the move connections for the buttons
print("Move Mobile Buttons deselected")
end)