Why is destroying a UI element causing player to completely stop moving?

When I destroy this UI element, it causes my player to completely freeze and movement completely stops. For no reason. I do have a function that I use to enable/disable movement. However, even tho I enable it in this code (And don’t disable it ever again) the player still has controls taken away from them.

In my code, I put a wait(5) to basically show that destroying the UI is what’s causing this issue. As after Movement(true) is fired, I can run around freely. But as soon as the UI is destroyed, my character is locked in place.

ezgif.com-gif-maker (23)
When I am spamming the camera movement, that is when I am also mashing the keyboard, trying to get some movement from my character, to no avail.

local function InputBegan(input, GPE)
	if GPE then return end
	
	if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
	
	if not Crystal:FindFirstChild("HP") then return end -- HP does not exist
	
	Crystal.HP.Value -= 1
	
	if Crystal.HP.Value <= 0 then
		Mined:FireServer(Crystal)
		
		Crystal:Destroy()
		
		Movement(true) -- Enable movement
		
		CameraManipulation.Reset()
		
		-- Set values to nil
		CurrentInteraction.Value = nil
		Mining.Value = nil
		
		wait(5)
		print("DESTROY")
		UI:Destroy() -- This prevents movement from fully working?
	end
end

UserInputService.InputBegan:Connect(InputBegan)
return function(active)
	print("MOVEMENT IS BEING SET TO: ", active)
	if active then
		PlayerControls:Enable()
	else
		PlayerControls:Disable()
	end
	
	MobileControls.Set(active) -- Disable mobile controls
end

Output
23:37:22.204 MOVEMENT IS BEING SET TO: false - Client - Movement:17
23:37:23.305 MOVEMENT IS BEING SET TO: true - Client - Movement:17
23:37:28.322 DESTROY - Client

As you can, the movement function NEVER fires false, after it’s fired as true. So it’s last time being fired is true, thus movement should stay active.

Is there a reason why you aren’t simply anchoring the character?

Anchoring the character has numerous flaws. In particular, if a player is moving while disabling then their body parts continue moving. Setting their humanoid stats doesn’t fix this issue either, as the character still gets stuck and can’t move.

Disabling player controls used to cause problems for me too. Either try:

  1. Running a loop to make their walk speed and jump power 0.
  2. Using body velocity and setting the velocity to 0 with a max force of math.huge

You could anchor the said moving body parts too?

That’s such a messy way to do this. This function works everywhere else in my game, and I use it over a dozen times in other instances with flawless results. I’m not gonna change it cause of it acting strangely in 1 use case, when this use case is clearly a bug on Roblox’s side

The problem isn’t due to disabling the controls. The problem is that destroying a UI element is for some unknown reason disabling the controls. My question is how can destroying a UI element disable the players controls?