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:
local part = Instance.new("Part") part.Position = Vector3.new(0, 5, 0) part.Size = Vector3.new(2, 2, 2) part.Parent = workspace local sphere = Instance.new("Part") sphere.Name = "LookVectorSphere" sphere.Position = workspace local increment = 1 local function movePartForward() part.Position = part.Position + (part.CFrame.LookVector*1) sphere.Position = sphere.Position + (part.CFrame.LookVector*1) end
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.
Fixed script from user bostaffmanbulgaria1 Who he stole from a guy that didn't know anything about scripting. Go ahead and use this!
-- The following script allows you to move the part, but not Up in the Y axis because I'm too stupid for this one... ---------------- -- LocalScript ---------------- local PlayerMouse = game.Players.LocalPlayer:GetMouse() local DraggablePart = game.Workspace.DraggablePart local PartPositionEvent = script.PartPositionEvent local Draggable = false local Target = nil PlayerMouse.Button1Down:Connect(function() Draggable = true repeat wait() if PlayerMouse.Target == DraggablePart then Target = PlayerMouse.Target Target.Position = Vector3.new(PlayerMouse.Hit.X, PlayerMouse.Hit.Y, PlayerMouse.Hit.Z) PartPositionEvent:FireServer(Target, Target.Position) end until Draggable == false end) PlayerMouse.Button1Up:Connect(function() Draggable = false end) ---------------------------------------------------------------------------------------------------------- -- Inside the Local Script put a Remote Event ------------------- -- ServerScript ------------------- script.Parent.OnServerEvent:Connect(function(player, Target, PartPosition) Target.Position = PartPosition end) --[[ You basically get the PlayerMouse's Target and if the target is THIS PART then allow the Position of this target to be the Hit of the mouse which the Hit is the position of THIS PART... Well. That about covers what I can do for you. --]]
-- The following script allows you to move the part, but not Up in the Y axis because I'm too stupid for this one... ---------------- -- LocalScript ---------------- local PlayerMouse = game.Players.LocalPlayer:GetMouse() local DraggablePart = game.Workspace.DraggablePart local PartPositionEvent = script.PartPositionEvent local Draggable = false local Target = nil PlayerMouse.Button1Down:Connect(function() Draggable = true repeat wait() if PlayerMouse.Target == DraggablePart then Target = PlayerMouse.Target Target.Position = Vector3.new(PlayerMouse.Hit.X, 1, PlayerMouse.Hit.Z) PartPositionEvent:FireServer(Target, Target.Position) end until Draggable == false end) PlayerMouse.Button1Up:Connect(function() Draggable = false end) ---------------------------------------------------------------------------------------------------------- -- Inside the Local Script put a Remote Event ------------------- -- ServerScript ------------------- script.Parent.OnServerEvent:Connect(function(player, Target, PartPosition) Target.Position = PartPosition end) --[[ You basically get the PlayerMouse's Target and if the target is THIS PART then allow the Position of this target to be the Hit of the mouse which the Hit is the position of THIS PART... Well. That about covers what I can do for you. --]]