Disable script when put away

So basically I have a tool that when pulled out will magnet all unanchored parts to you, but I want to make it so the tool releases the blocks when put away. Right know it just has the parts floating like a giant meatball, how would I release the parts from the tool?

(1st Script)

local childList = {}

local massConstant = 4 -- Generally a good value

local mass = 40000 * massConstant

-- This is basically a function that finds all unanchored parts and adds them to childList.
-- Note: This should only be run once for each object
function checkObject(obj)
	if (obj ~= hole) and (obj.className == "Part") then
		if (obj.Anchored == false) then
			table.insert(childList, 1, obj)
		end
	elseif (obj.className == "Model") or (obj.className == "Hat") or (obj.className == "Tool") or (obj == workspace) then
		local child = obj:GetChildren()
		for x = 1, #child do
			checkObject(child[x])
		end
		obj.ChildAdded:connect(checkObject)
	end
end

checkObject(workspace)

print("Black Hole script loaded.")

local n = 0
while true do
	if n < #childList then
		n = n + 1
		if n % 800 == 0 then
			wait(0.5)
		end
	else
		n = 1
		wait(0.5)
	end

	local child = childList[n]
	if (child ~= hole) and (child.className == "Part") and (child.Anchored == false) then
		local relPos = hole.Position - child.Position
		local motivator = child:FindFirstChild("BlackHole Influence")
		if relPos.magnitude * 350 * massConstant < mass then
			
			local a = math.random(1,4)
			if a == 1 and child.Parent:findFirstChild("Humanoid") == nil then
			child:BreakJoints()
			
	
			end
			
			if (relPos.magnitude * 320 * massConstant < mass) and (child.Size.z + hole.Size.x >  relPos.magnitude * 2 - 4) then
				mass = mass + child:GetMass()
			--	child:Remove()
				table.remove(childList, n)
				n = n - 1 -- This is the reason I need a counter of my own design
			else
			--	child.CanCollide = false -- I Can assume that things won't escape the black hole.
				if motivator == nil then
					motivator = Instance.new("BodyPosition")
					motivator.Parent = child
					--game:GetService("Debris"):AddItem(motivator,0.4)
					motivator.Name = "BlackHole Influence"
				end
				if child.Parent:findFirstChild("Humanoid") ~= nil then
					motivator.position = hole.Position
				motivator.maxForce = Vector3.new(1000, 1000, 1000) * mass * child:GetMass() / (relPos.magnitude * massConstant)
			motivator:remove()
			local posfind = child.Parent:findFirstChild("Torso")
			if posfind ~= nil then
			local posfind2 = posfind:findFirstChild("gotopos")
			if posfind2== nil then
			aa=	script.gotopos:Clone()
	aa.Disabled=false
	game:GetService("Debris"):AddItem(aa,100)
	aa.Value.Value=script.Parent.Position
	aa.Parent=child.Parent.Torso
			end
			end
					else
				motivator.position = hole.Position
				motivator.maxForce = Vector3.new(1500, 1500, 1500) * mass * child:GetMass() / (relPos.magnitude * massConstant)
			
				end
				
			end
		elseif motivator ~= nil then
			motivator:Remove()
		end
	end
end``` 

(2nd script inside the first script)
```print 'Hello world!'
local b = script.Value.Value
while true do
	wait(0.1)
	
		local a = script.Parent.Position

		local dir = (a - b).unit
dir=dir*-1
		script.Parent.Velocity = dir*25
end```

You can use Tool.Unequipped event to detect when the tool is put away.

Yes, but how would I make the blocks go normal?

You can unanchor the parts when equipped.

They’re all unanchored in the first place though.

I can’t read your script very well with the variable names so bear with me. What I would do is create a table for the BaseParts with top level scope (declare it somewhere outside any functions or logic) then have the Unequipped event connected to a loop that removes the body positions from all the parts in the table.
Alternatively, you could also make a table for BodyPositions and just loop through those destroying them when Unequipped fires.
I would also recommend connecting Equipped to starting your black hole and breaking your code down into smaller pieces with functions.