Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to create draggable parts like building tools?

Asked by
aredanks 117
5 years ago

I have a scripted tool that lets me create parts then move them as accordingly to my desire but I want to be able to allow dragging like real functional building tools. Let's say I have a part which is one of the spheres (that represents forward), how would I make it that if I wanted to drag it, it would keep moving it?

Here is a basic idea of my script, it should be simple to understand:

01local part = Instance.new("Part")
02part.Position = Vector3.new(0, 5, 0)
03part.Size = Vector3.new(2, 2, 2)
04part.Parent = workspace
05local sphere = Instance.new("Part")
06sphere.Name = "LookVectorSphere"
07sphere.Position = workspace
08 
09local increment = 1
10 
11local function movePartForward()
12    part.Position = part.Position + (part.CFrame.LookVector*1)
13    sphere.Position = sphere.Position + (part.CFrame.LookVector*1)
14end

This is just an example to make it clear and easy of what I'm asking so I will only be asking for that one sphere example I gave.

2 answers

Log in to vote
1
Answered by
Lakodex 711 Moderation Voter
5 years ago

Fixed script from user bostaffmanbulgaria1 Who he stole from a guy that didn't know anything about scripting. Go ahead and use this!

01-- The following script allows you to move the part, but not Up in the Y axis because I'm too stupid for this one...
02 
03----------------
04-- LocalScript
05----------------
06local PlayerMouse = game.Players.LocalPlayer:GetMouse()
07local DraggablePart = game.Workspace.DraggablePart
08local PartPositionEvent = script.PartPositionEvent
09local Draggable = false
10local Target = nil
11 
12 
13PlayerMouse.Button1Down:Connect(function()
14    Draggable = true
15    repeat
View all 44 lines...
0
Well If you don't know something then Google is your friend as always. I see that you've added "PlayerMouse.Hit.Y" which I did not add for a reason. Whenever the Part is being dragged it comes to the position of the camera. Basically like a following NPC. That is why I used a number instead of Mouse.Hit.Y bostaffmanbulgaria1 89 — 5y
0
No. Its just because you used google and was a lazy sack of shit and just wanted reputation. Lakodex 711 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01-- The following script allows you to move the part, but not Up in the Y axis because I'm too stupid for this one...
02 
03----------------
04-- LocalScript
05----------------
06local PlayerMouse = game.Players.LocalPlayer:GetMouse()
07local DraggablePart = game.Workspace.DraggablePart
08local PartPositionEvent = script.PartPositionEvent
09local Draggable = false
10local Target = nil
11 
12 
13PlayerMouse.Button1Down:Connect(function()
14    Draggable = true
15    repeat
View all 44 lines...
0
What if i want it to be incrementable? This seems to move too precisely? Would I use math.floor? aredanks 117 — 5y

Answer this question