If I understood the problem correctly, it might be because the part you are moving affects determining mouse.Hit. You can prevent this by setting mouse.TargetFilter to instance. I’d also recommend simplifying your current onClick functions and have a function they all call, to prevent unnecessary code repetition.
It’d also be a little more efficient to store all your functions in local variables. If you want to define a function below the line where it’s called, you can declare the variable before that line and set its value to the function on any line you want to.
local function onClick(partType)
selected.Value = partType
if instance then
instance:Destroy()
end
instance = createTransparentInstance(partType)
mouse.TargetFilter = instance
end
function onPartClick()
onClick("Part")
end
function onSphereClick()
onClick("Sphere")
end
function onWedgeClick()
onClick("Wedge")
end
function onCylinderClick()
onClick("Cylinder")
end