Most of the time it doesn't properly Un anchore my character

My script only works sometimes, most of the time it doesn’t properly Un anchore my character

local UIS = game:GetService(“UserInputService”)
local player = game:GetService(“Players”).LocalPlayer

local Char = player.Character or player.CharacterAdded:Wait()
repeat wait()

until Char

local Rep = game:GetService(“ReplicatedStorage”)
local Remote = Rep:WaitForChild(“Practice_Remote”)

local debounce = 1
local Mouse = player:GetMouse()

UIS.InputBegan:Connect(function(input,istyping)
if not istyping then
if input.KeyCode == Enum.KeyCode.F and debounce == 1 then
debounce = 2
anim = player.Character:WaitForChild(“Humanoid”):LoadAnimation(script.Hold)
anim:Play()

		for i = 1,math.huge do
			if debounce == 2 then wait() 
				
				player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position,Mouse.Hit.p)
				player.Character.HumanoidRootPart.Anchored = true
				
			else
				break
			end
			wait()
		end
	end
end

end)

UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F and debounce == 2 then
debounce = 3
anim:Stop()
if player.Character.HumanoidRootPart.Anchored == true then
player.Character.HumanoidRootPart.Anchored = false

	end
	wait(1)
	debounce = 1
end

end)

Use this:

player.Character:WaitForChild("HumanoidRootPart").Anchored = false 

instead of this:

if player.Character.HumanoidRootPart.Anchored == true then
player.Character.HumanoidRootPart.Anchored = false
end

I tried it and it still doesn’t work sadly.

Oh i thin I know whats the error. You forgot a check function in the Input Ended function. You have to add: “if not istyping then”
Hope this fixes the problem!