Dragging objects with the mouse

I am just suggesting that what ever method is being used to select the part you want to move there should be some way to detect the object you are trying to select and if it has a Humanoid child then reject the selection.

3 Likes

Is there any chance this can be range limited, so players cant pick up an item from the other side of the map, nor place it incredibly far?

2 Likes

This is really easy to implement by yourself, you could fork my module and add this simple functionality to it by adding an extra argument and a condition, but you can find that in this file:

even_better_dragging.rbxl (33.4 KB)

4 Likes

how can I change it so I can drag it with proxyprompt?
edit: it doesn’t work with a normal brick, but the bricks in the example are normal bricks with a decal (except for c) so what script do I have to change?

1 Like

This is a really great tutorial well done!
It’s good to understand and it works perfectly for me.

Unfortunately I did after a while run into one problem.
After I accidentally died testing something the dragging stopped working so I tested it again and yes, dying stops it from working (for me). Perhaps it’s due to something I added into the script since I couldn’t find anyone here with the same problem.

However this is litterally the only change I made:

	if target and target.Name ~= "Workspace" and not(target.Anchored) then

Into:

local toypart = target:FindFirstChild("ToyPart")
	if target and target.Name ~= "Workspace" and not(target.Anchored) and toypart ~= nil and toypart.Value == true then

So it’s checks an object for a bool value before allowing it to be dragged (which works).

Not sure if you can help me out but regardless of this it’s still an amazing tutorial!

4 Likes

The problem is with the basic script sample I don’t update the character variable each time the mouse clicks, it uses a character variable initialized when the script starts executing, meaning if he dies and a new character spawns, it won’t do anything relative to that character because it’s still referring to the old character. This is a mistake a lot of people fall into, so watch out.

Updating the character inside of the event will fix it, but a nicer solution is just putting the script in StarterCharacterScripts instead of the Player’s.

2 Likes

Very well written tutorial, you can’t imagine how much this has helped me! :smile:

2 Likes

Sorry for the late reply but thanks a lot for your help! :slight_smile:
It works perfectly now and I also understand why it stopped working.
Again thanks for this great tutorial!

2 Likes

Is there a way to make the player drag the whole object instead?

1 Like

That’s already what happens. If you have a model for example, you would need to weld the parts together so they are physically the same asssembly, that way any part you drag that’s part’s of the model will drag everything with it.

1 Like

No i mean i want to drag the whole thing all together instead doing it on one POINT.

1 Like

Silly question, (because it probably is impossible) but do you think this is possible on a mobile device? Great tutorial though.

1 Like

If there are lots of parts welded together, its not “strong” enough to pull it up

2 Likes

As a long time LT2 player, I think this is one of the coolest creations I have seen on the devforum. Great job.

1 Like

Of course! The article only makes it register keyboard input, but you can easily make it work for mobile (I recommend research on the matter).

If there are lots of parts welded together, its not “strong” enough to pull it up

Indeed, you can either toggle RigidityEnabled on (this makes it ignore all physical properties and do its maximum to get to the destination), or increase the force, but hardcoding is bad, so you can make the force proportional to the mass of the assembly!

An example:

gripAlignPosition.MaxForce = object.AssemblyMass * 30000 -- AssemeblyMass is the mass of all connected parts together
3 Likes

Oh ok, thanks! Just one more thing I wanted to say, I noticed a bug with the system, and it’s when you grab a part, then reset, you aren’t able to grab anything after that. Since I’m not a good programmer, how would I fix this bug? (I’m using this for my game, and there might be something in it that is causing this)

Yay! I fixed it! Just go into the module script and create a new line after line 72, and add this line of code

character = player.Character
1 Like

Heyy! Very nice script, it is exactly what I was looking for (I’m making a telekinesis ability lol). Is there a way to add particles to it (server-sided particles, not locally)? I’m also very new to scripting so any help will be useful

I know I am probably necroposting by now because the last reply was four months ago, but here is a heads-up for anyone who uses this tutorial/used the download in the tutorial, the mouse module this dragging script uses has a memory leak!! It’s probably better to use :GetMouse() on the player instead of using the module. Just use Mouse.Move for the dragging connection, it is a little buggy, but it works.

2 Likes

Oh no!!! I knew that thing wasn’t ready to be published for the community, can you inform me more about the issue?

Simply by clicking a lot on a brick/autoclicking a brick will start growing lag. Microprofile will say nothing, so I am not sure how to describe this issue, but all I know is that the MouseModule has a bug in it that causes lag. To add onto this bug, exploiters can use the remote event to manipulate characters