When the player clicks their mouse you can start by checking if the mouse.Target is a specific part, then if it is you allow the dragging part to be dragged to the mouse.Hit(but you may want to offset the position by the size of the part–mouse.Hit.Position + Vector3.new(0, Part.Size.Y / 2, 0) or something similar)
I would use RunService.RenderStepped event which fires before each frame
run.RenderStepped:Connect(function()
-- Mouse.Target is the BasePart the mouse hit, if no BasePart it will return nil
if mouse.Target == workspace.Baseplate then
-- Mouse.Hit is the CFrame in 3d space that the mouse hits
draggingPart.CFrame = Mouse.Hit
-- you might want to add offset like @DrKittyWaffles said
end
end)
It might be more effective to use raycasting anyway this is how I would have
what he is trying to do set up
game:GetService("RunService").RenderStepped:connect(function()
-- construct ray
local mouseRay = mouse.UnitRay
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {item,player.Character}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- cast ray
local raycastResult = game.Workspace:Raycast(mouseRay.Origin,mouseRay.Direction.unit * MAX_PLACEMENT_DISTANCE,rayCastParams)
if raycastResult then
target = raycastResult.Instance:GetFullName() -- BasePart ray hit
pos = raycastResult.Position -- Vector3 Position ray hit
norm = raycastResult.Normal -- surface normal ray hit
local endPos = pos + (norm * (item.PrimaryPart.Size*.5)) -- this math will offset the part so they don't intersect
item:SetPrimaryPartCFrame(CFrame.new(endPos)) -- set draggingpart CFrame
end
end)