SelectionEngine stopped working for no reason with no edits after ~a day

I wanted to re-create the Selection Engine in Roblox Studio whenever you click on an unlocked Part, or when you move your mouse in/out of said Part. However, it randomly stopped working yesterday and I can’t figure out why.

It hangs on “debugprint(“Destroy line 50”)”, and everything I’ve done so far hasn’t fixed it. Here’s my code:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local debugprintenabled = true

local selectedObject = nil

local tweenService = game:GetService("TweenService")

local function debugprint(message)
	if debugprintenabled then
		if message ~= nil then
			print(message)
		else
			print("DebugPrint failed because message is nil")
		end
	end
end

coroutine.wrap(function()
	while true do
		local target = mouse.Target
		if target ~= nil and selectedObject ~= target then
			debugprint("Found Target")
			if target:IsA("BasePart") or target:IsA("Model") and not script.Parent:FindFirstChild("HoverBox") then
				debugprint("Found Target 2")
				if target:IsA("BasePart") and target.Locked == false then
					mouse.Icon = "rbxassetid://6641893605"
					selectionBox = game.ReplicatedStorage:WaitForChild("HoverBox"):Clone()
					selectionBox.Parent = script.Parent
					selectionBox.Adornee = target
					local tween_01 = tweenService:Create(selectionBox, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), { Color3 = Color3.fromRGB(178, 229, 255) })
					local tween_02 = tweenService:Create(selectionBox, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), { Color3 = Color3.fromRGB(25, 153, 255) })
					
					repeat
						tween_01:Play()
						wait(1)
						tween_02:Play()
						wait(1)
					until not script.Parent:FindFirstChild("HoverBox")
				else
					debugprint("Target is Locked")
				end
			elseif not target:IsA("BasePart") and selectionBox ~= nil then
				script.Parent:FindFirstChild("HoverBox"):Destroy()
				debugprint("Destroy line 46")
				mouse.Icon = "rbxasset://textures/ArrowFarCursor.png"
			end
		elseif target == nil and selectionBox ~= nil then
			script.Parent:FindFirstChild("HoverBox"):Destroy()
			debugprint("Destroy line 50")
			mouse.Icon = "rbxasset://textures/ArrowFarCursor.png"
		end
		
		mouse.Button1Down:Connect(function()
			local target = mouse.Target
			if target ~= nil then
				if target:IsA("BasePart") or target:IsA("Model") then
					if script.Parent:FindFirstChild("HoverBox") then
						script.Parent:FindFirstChild("HoverBox"):Destroy()
					end

					if script.Parent:FindFirstChild("SelectedBox") then
						script.Parent:FindFirstChild("SelectedBox"):Destroy()
					end

					if target:IsA("BasePart") and target.Locked == false then
						selectedObject = target

						debugprint("Selected object: "..tostring(selectedObject))

						local selectionBox_01 = game.ReplicatedStorage:WaitForChild("SelectedBox"):Clone()
						selectionBox_01.Parent = script.Parent
						selectionBox_01.Adornee = target
					end
				end
			end
		end)
		
		wait()
	end
end)()

(there’s probably a better way to replicate behavior this btw)

Update: It seems as though whenever I remove the spawn function, it starts working, but the function to destroy the SelectionBox is not able to be reached. I also made a couple of changes to the code which can be seen in the edit.