I've got this tool going that I retrofitted from a HopperBin. In theory, and by all known laws of RBX.Lua, this script should work, unless I'm overlooking something. The script is below; I've done my best to document it.
s = false --This tells if the tool is selected, used to stop updatePos()
function onSelected(mouse) --Should fire when mouse is selected
print ("selected")
s = true --Indicates that the mouse is selected
t = Instance.new("Part") --From here until line 15 it makes the part
t.Anchored = true
t.FormFactor = 2
t.BottomSurface = "Smooth"
t.TopSurface = "Smooth"
t.BrickColor = BrickColor.new(Color3.new(math.random(0,1), math.random(0,1), math.random(0,1)))
t.Transparency = 0.3
t.Position = mouse.Hit.p --This is corrected in updatePos()
t.Size = Vector3.new(4, 0.2, 4)
t.Parent = game.Workspace
repeat updatePos(t, mouse) until s == false --Will repeat updatePos() until unselected
t:Destroy() --Removes part after unselected, as the loop won't run this code until it is done
end
function onDeselected() --Fires when deselcted, destroys the part...
s = false
end
function updatePos(object, pos) --This one updates the part's position to corespond with the mouse's position, corrected to the nearest stud
object.Position = Vector3.new(math.ceil(pos.Hit.x), object.Size.Y/2, math.ceil(pos.Hit.z))
wait(0.0001)
end
script.Parent.Equipped:connect(onSelected) --Fires when equipped
script.Parent.Unequipped:connect(onDeselected) --Fires when unequipped
This script (in HopperBin form) worked exactly as it was supposed to. There are no errors thrown with this, and nothing from here appears in the output.

1 comment
Worked! Thanks!