this script allows you to place an item on the ground when you click on a button, then the ground, but I want the script to be completed when the item is placed on the ground. Instead, if i re-forage the item it automatically allows me to place it again which i don't want. It seems like the script is still "open" in a way if that makes sense. What I'm trying to figure out is how to make the script completely end so that you have to press the button again to place the item again. Let me know if you need me to clarify anything. Thanks!

local BUTTON = script.Parent
local player = game.Players.LocalPlayer
local CURRENT = nil
local mouse = player:GetMouse()
local RANGE = 15


function do_remove_all(parent)
	local children = parent:GetChildren()

	for index, child in pairs(children) do
		child:remove()
	end
end

function rangeCheck(mouse)
	local char = player.Character
	local torso = char.Torso

	return (torso.Position - mouse.hit.p).magnitude < RANGE
end



function removeExample()
	local player = game.Players.LocalPlayer
	local char = player.Character

	local ex_check = char:findFirstChild("BACKPACK_EXAMPLE")

	if ex_check ~= nil then
		ex_check:remove()
	end
end


function onMouseMove(mouse)
	local player = game.Players.LocalPlayer
	local char = player.Character
	local torso = char.Torso
	local pack = player:findFirstChild("Pack")
local pack_tab = pack:GetChildren()
local partname = BUTTON.Text
local part = pack:FindFirstChild(partname)

	removeExample()
	
	
		if rangeCheck(mouse) then
			
			local example = part:Clone()
			example.Name = "BACKPACK_EXAMPLE"
			example.Locked = true
			example.Transparency = 0.5
			example.Parent = char
			example.Position = mouse.hit.p
			do_remove_all(example)
			
		end
	end


function onButton1Down(mouse)
	local pack = player:findFirstChild("Pack")
local pack_tab = pack:GetChildren()
local partname = BUTTON.Text
local part = pack:FindFirstChild(partname)
local player = game.Players.LocalPlayer
local char = player.Character

	if part ~= nil then
		if rangeCheck(mouse) then
			print("clicked")

			part.Parent = game.Workspace
			part.Locked = false
			part.Anchored = false
			part.Position = mouse.hit.p
			
			removeExample()
			part = nil
	end
	end
	end

function onKeyDown(key, mouse)
	if key == "r" then
		removeExample()
		local CURRENT = nil
	elseif key == "e" then
		local player = game.Players.LocalPlayer
		local pack = player:findFirstChild("Pack")
		local pack_tab = pack:GetChildren()

		for index, child in pairs(pack_tab) do
			local CURRENT = child
			onButton1Down(mouse)
			wait(0.1)
		end

		local CURRENT = nil
	end
end

function onMouseButton1Down()

		print("buttonclicked")
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Move:connect(function() onMouseMove(mouse) end)
	mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)

end

BUTTON.MouseButton1Down:connect(onMouseButton1Down)