-
What do you want to achieve? Keep it simple and clear!
A part dragging script with dragging exactly like in Roblox Studio. -
What is the issue? Include screenshots / videos if possible!
My part dragging script doesn’t exactly work like in Roblox Studio. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking into the scripts of f3x building tools, because their dragging system is the same as in Roblox Studio, but the code was too hard for me to understand.
Heres the main part in my current part dragging sytem:
-- some functions used in the main loop
function rayCast(params)
local mousePos = UserInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePos.X, mousePos.Y)
local rayCastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 2048, params)
return rayCastResult
end
function roundPos(position, roundTo)
return Vector3.new(math.round(position.X/roundTo)*roundTo, math.round(position.Y/roundTo)*roundTo, math.round(position.Z/roundTo)*roundTo)
end
-- some variables for the main loop
local offset
local startPos = part.Position
-- main loop
local connection = RunService.RenderStepped:Connect(function()
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {part, player.Character, workspace.SpawnLocation}
rayCastResult = rayCast(params)
if rayCastResult then
part.Position = rayCastResult.Position + Vector3.new(0, part.Size.Y/2, 0)
part.Position = roundPos(part.Position, 1)
if not offset then
offset = startPos - part.Position
offset = Vector3.new(offset.X, 0, offset.Z)
end
part.Position += offset
end
end)
while true do
if UserInputService.InputEnded:Wait().UserInputType == Enum.UserInputType.MouseButton1 then break end
end
connection:Disconnect()
If there are any uncertainties about the code please let me know and I’ll try to explain it as well as I can.
If you will be able to write a part dragging script that feels just like part dragging in Roblox Studio in the similar format as the script above I will be really grateful. I also might give you a little something😏