Activing drag detector using input/key

How would I be able to assign a key to activate a drag detector? In my case, I want the player to be able to drag stuff with E, but NOT with left click. I already have the raycasting and code that is needed to detect what the player wants to drag, but I am not sure how I can active the drag detector.

3 Likes

U mean this?

local UIS = game:GetService("UserInputService")

local Dragging = false

UIS.InputBegan:Connect(function(i,ini)
	
	if ini then return end
	
	if i.KeyCode == Enum.KeyCode.E then
		
		Dragging = true
		print("_Current State: "..Dragging)
		
		-- Make here start dragging
		
	end
	
end)

UIS.InputEnded:Connect(function(i,ini)

	if ini then return end

	if i.KeyCode == Enum.KeyCode.E then

		Dragging = false
		print("_Current State: "..Dragging)
		
		-- Make here stop dragging

	end

end)
2 Likes

the ā€œ-- Make here start draggingā€ part is where the problem is. I canā€™t find any function or property in a Drag Detector that I can use or change to force the player to drag.

uhhh
u mean it?
Š”Š½ŠøŠ¼Š¾Šŗ эŠŗрŠ°Š½Š° 2024-06-06 Š² 18.41.52

1 Like

yes, i mean that, a drag detector.

Well, then, Iā€™ll put it this way.
Drag detector is used only for mouse tracking.

In your case, if you want to make Drag Detector to be, it will only be there :slight_smile: (for looks)

You need to write a code that when you hover the mouse over an object, that object will be dragged when you click on the E button.

for example, in local script

CurrentItem = nil

(when hovering over an item) CurrentItem will be equal to the Item that the player hovered the mouse over, if the player does not hover over an item, CurrentItem will also be equal to nil.

In the script you should make a function when pressing the E button, so that the condition:
( if mouse.Target.Parent.Name == CurrentItem then )
ā€¦ ur drag func

I dont quite get it?

The drag detector actually drags the item with the mouse without further code. My game is first person so in this case you move your camera to drag the object with you. I want the drag detector get activated when you press a key. Iā€™ve already coded the inputs, and I am using raycasts to detect what the player is trying to drag. The last missing step that I canā€™t quite get is activating the drag detector, this means I have no drag function because the Drag Detector is already handling that.

1 Like

You can use Tags to keep track of whether something you want to drag or not.

like in this video:

In that case I canā€™t help you, sorry.

I have never used a drag detector in the 6 years I have been in business. xd

I have now looked through all the Drag Detector information myself. I havenā€™t found anything related to changing the input.

I donā€™t think you can do that, or you need to write your own drag detector (mimicking a real drag detector) and then change the input.

Or maybe make it so that when you press E button, MouseButton1 is automatically pressed if you move the cursor over the object you want to drag.

Also, I found something similar to change input button, but it doesnā€™t work :frowning: (screenshot below)

Š”Š½ŠøŠ¼Š¾Šŗ эŠŗрŠ°Š½Š° 2024-06-06 Š² 19.17.20

1 Like

Has anyone figured out how to do this?