I need help with a touched script

I am trying to make a script when you touch a part your HumanoidRootPart gets anchored
and a function is called to check whenever you jump and whenever you do jump your HumanoidRootPart gets unanchored this side of the script works pretty good but the problem is I don’t know how to stop the function I have tried return and break but both of these don’t seem to work
I will appreciate your knowledge on this

script.Parent.Touched:Connect(function(PartThatTouched)
	if PartThatTouched.Name == "HumanoidRootPart" then
		local plr = game.Players:FindFirstChild(PartThatTouched.Parent.Name)
		local char = plr.Character
		local rootpart = char.HumanoidRootPart
		local humanoid = char:FindFirstChild("Humanoid")
		rootpart.Anchored = true
		humanoid:GetPropertyChangedSignal("Jump"):connect(function()
			print("Player Has Jumped")
			rootpart.Anchored = false
		end)
	end
end)

This video may explain more:


as you can tell the function is still repeating and this will cause problems with other scripts

You could make a variable to turn it on and off. Here’s what it will look like:

local enabled = true

script.Parent.Touched:Connect(function(PartThatTouched)
    if enabled then
	if PartThatTouched.Name == "HumanoidRootPart" then
		local plr = game.Players:FindFirstChild(PartThatTouched.Parent.Name)
		local char = plr.Character
		local rootpart = char.HumanoidRootPart
		local humanoid = char:FindFirstChild("Humanoid")
		rootpart.Anchored = true
		humanoid:GetPropertyChangedSignal("Jump"):connect(function()
			print("Player Has Jumped")
			rootpart.Anchored = false
		end)
	end
   end
end)

I also think that a debounce would be a good idea for touched events.

Not sure why I didn’t think of this but thanks bud seem to work
Probably because I’ve been up for since yesterday