I'm trying to make a tool that, while it is equipped and the player holding the tool's mouse is over an unlocked part, a SelectionBox is created on the part.

It's a LocalScript directly in a tool (without RequiresHandle):

repeat wait() until game.Players.LocalPlayer ~= nil
local p = game.Players.LocalPlayer

local holding

local mouse = p:GetMouse()
local target = mouse.Target

script.Parent.Equipped:connect(function()
	holding = true
end)

script.Parent.Unequipped:connect(function()
	holding = false
end)

while holding == true do
	if target ~= nil then
		target.Changed:connect(function(newTarget)
			target = newTarget
			if target.Locked ~= true then
				local box = Instance.new("SelectionBox", target)
				box.Adornee = target
				box.LineThickness = 0.1
				box.Color3 = Color3.fromRGB(255,128,0)
			end
		end)
	end
end