Dragging objects with the mouse

All the settings are set the same as the original part, however when I put the value into the newly created part it simply does not work.

1 Like

Are you :Clone()ing the part and moving the cloned part? Your problem seems off-topic from this article’s premise, maybe make a #help-and-feedback:scripting-support topic.

1 Like

Forgive me as i am quite new to scripting but:

Adding a maximum range to the object seems to break everything

mouse.Target.Position = mouse.Hit.Position.Unit * 20
when I do that i get the error
players.crolaa.PlayerScripts.LocalScript:18: attempt to index nil with ‘Position’

So first i thought, hey maybe I typed something in wrong, eventually got to the point of retyping everything then just copy and pasting.

None of which fixed or helped at all.

I have no clue what is causing this and would appreciate some help.

Great tutorial by the way, Very useful stuff.

3 Likes

This means that either Target is nil, are you checking if it’s not nil?

if mouse.Target ~= nil then
2 Likes

Position setting requires you to use a Vector3 so look at doing that next.

1 Like

It is a vector3

mouse.Hit.Position.Unit * 20

does yield a Vector3

Or do you mean something else?

2 Likes

sorry my bad. I thought .unit was just a number not a normalised vector3

3 Likes

Thank you for the response, i will come back with results later.

1 Like

Just checked the script and yes I am checking if it is nil.

I’ll keep messing with stuff to find a fix

2 Likes

I’ve gotten most fixed, I’m trying to make this compatible with a R6 ragdoll script i made, only issue being is that it gets thrown into the exosphere whenever i click on them, Physics do not carry over into the part, and it isn’t as smooth as in this image:

mn9upadnk.cloudfront.net/uploads/default/original/4X/6/4/2/64252e8e46f22be64659853d6f0fd65befada680.gif

Thanks in advance!

4 Likes

Nice tutorial! It definitely helped me alot. I just want to ask how to make it so the part doesn’t go underground.

3 Likes

Thank you! Can you send a picture of it happening? Sounds like an annoying bug

2 Likes

this works perfectly! The only problem I have is that whenever I try to make it only happen to parts with a specific name, it dose not work. Is there a way to make this only start when a part has a specific name? Just so not every thing is able to be picked up.

2 Likes

you could use values and if scripts.

Never mind, I found out how to do it myself.

1 Like

awesome! thank you! i have a question though, what are the locations of the part and the things inside it? i tried reading through the tutorial but you lost me halfway. i guess inserting a script inside the part wouldnt work. lol

2 Likes

A BodyPosition and BodyGyro (even though these guys are legacy now, I should update the article) are inserted inside of the object, and destroyed after. The script doesn’t need to be inside of a part, you can just put it anywhere the client can see it, maybe StarterPlayerScripts, only thing special about the part is that it’s unanchored else the bodymovers won’t work. Also I’d appreciate it if you take a moment to explore deeper what the article is about! It wasn’t made so you can copy paste the end product, but to salvage info from it.

2 Likes

okay, so I need to insert a bodygyro and body position, I though those were automatically by the script, that’s why. So I’m guessing since I can place the script anywhere that means I should somewhere address the parts location?
I’m also pretty new/bad at scripting so I was wondering if the different addressed script parts should be merged together or the last script is the final product?

1 Like

You see, you don’t need to address each part in the game. Each time the player grabs a part, that part is given to the script by mouse.Target. Then any operation you want to do on the part, you edit mouse.Target.

As for your second question, the script is a stand-alone thing, it’s indepedent on the parts you use. In this article I don’t cover how you would restrict grabbing certain parts, but to do that you can just name parts that are supposed to be dragged a special name, and when Button1Down is fired you check if the current clicked part is named that special name.

2 Likes

but for me the script doesnt work, i used the last script and was confused at first on some things but this explanation helped me. though, even when the script is inside a part it doesnt work, i guess its location is wrong?

1 Like