sorry my bad. I thought .unit was just a number not a normalised vector3
Thank you for the response, i will come back with results later.
Just checked the script and yes I am checking if it is nil.
I’ll keep messing with stuff to find a fix
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:
Thanks in advance!
Nice tutorial! It definitely helped me alot. I just want to ask how to make it so the part doesn’t go underground.
Thank you! Can you send a picture of it happening? Sounds like an annoying bug
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.
you could use values and if scripts.
Never mind, I found out how to do it myself.
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
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.
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?
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.
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?
I told you in the previous reply that it’s supposed to be placed somewhere in the client, doesn’t necessarily have to be a part. Place it in StarterGui for a start.
its in startergui, is it supossed to be a local or normal script? also, is the last script you mentioned in the OP post the finished one?
Me and my friend used this and I say good job. For anyone wondering how to drag a model just weld it.
am i able to just copy paste the last part of code?
For me it only works in Studio
Do you have to be R6, and does it being in a localscript matter? (It’s in StarterPlayerScripts as a localscript)
Did I miss something?
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService") --we will use this service for something later
local target
local down
function mouseHit(distance)
local ray = Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * distance) --as you can see, here creating a ray with the same origin (which is the camera of course) and the same direction BUT longer, whatever the distance parameter is
local _, position = workspace:FindPartOnRay(ray)
return position
end
if mouse.Target ~= nil then
mouse.Target.Position = mouseHit(20)
mouse.Target.Position = camera.CFrame.Position + (mouse.Hit.Position.Unit * 20)
end
mouse.Button1Down:connect(function()
if mouse.Target ~= nil and mouse.Target.Locked == false then
target = mouse.Target
mouse.TargetFilter = target
down = true
local gyro = Instance.new("BodyGyro") --adding the forces
gyro.Name = "Gyro"
gyro.Parent = target
gyro.MaxTorque = Vector3.new(500000, 500000, 500000)
local force = Instance.new("BodyPosition")
force.Name = "Force"
force.Parent = target
force.MaxForce = Vector3.new(10000, 10000, 10000) --you may wanna modify this a bit, since it effect if you can move an object or wrong depending on its weight/mass (in other words, the force might not be strong enough)
end
end)
game:GetService("RunService").RenderStepped:Connect(function() --replaced the move event with renderstepped because it works better in some cases, renderstepped is an event that fires every frame, basically super fast, look it up it is important!
if down == true and target ~= nil then
target.Gyro.CFrame = target.CFrame --this is to keep rotation
target.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 20)
end
end)
mouse.Button1Up:connect(function()
if target then --of course we wanna remove the forces after the dragging, first check if there was even a target
if target:FindFirstChild("Gyro") or target:FindFirstChild("Force") then --check if there was a force
target.Gyro:Destroy() --DESTROY!!!!
target.Force:Destroy()
end
end
down = false
mouse.TargetFilter = nil
target = nil
end)```
A small nitpick: There are some inconsistent naming of Connect
. You should name all of them to Connect
to avoid confusion and that way, many newbies viewing this article will not use deprecated functions.