How do I force a player to let go of something with a DragDetector?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I have a custom joystick with a UIDragDetector. When the joystick disappears (not destroyed), I want to make the player let go of the drag detector

  2. What is the issue? Include screenshots / videos if possible!
    When the Gui object’s Visible property is disabled, the player will still be dragging the UIDragDetector, and it will send any changes in input, which will cause an issue in my game

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking for solutions, but I didn’t find anything relevant

I need to be able to hide the joystick due to changes in the state of the game, as the joystick is only meant to appear in certain circumstances

I could just make the UIDragDetector.DragContinue event stop sending changes in input, but it doesn’t feel like an ideal solution

Here is the aforementioned solution:

dragDetector.DragContinue:Connect(function()
	if joystickHandle.Parent.Visible then -- this if statement is what I mean
		local joystickX = (joystickHandle.Position.X.Scale - 0.5) * 2
		local joystickY = (joystickHandle.Position.Y.Scale - 0.5) * 2
		local joystickPosition = Vector2.new(joystickX, -joystickY).Unit
		bindableJoystickEvent:Fire(joystickPosition) -- sends info to other LocalScripts
	end
end)

The player would still be able to drag the UIDragDetector, but at least it wont send anything. Is there a better solution?

1 Like

This might be really wrong, but can’t you just disable the drag detector by making the UIDragDetector’s Enabled Boolean set to false, right after you turn off the Gui objects visibility is disabled?

2 Likes

After testing in studio, disabling the DragDetector while it is being dragged breaks it completely, causing this indicator thing to stay stuck on screen:
image
as for the joystick itself, it no longer moves, and it is stuck in the center, even if the DragDetector is enabled. Same result using the actual Roblox app on mobile.