Help with debounce!

Heyo Devforum! Recently, I have been trying to create a functional balloon using body forces, but I have run into a problem where multiple body forces are inserted at a time.

Here is my script inside a part:

script.Parent.Touched:Connect(function(hit)
	local balloon = script.Balloon
	local holderpart = balloon.Holder
	local timeuntilpop = script.Parent.Parent.TimeUntilPop
	local animation = script.BalloonHold
	local isonb = false
	if hit.Parent:FindFirstChild("Humanoid") and not isonb then
		isonb = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local character = hit.Parent
		local humanoid = character.Humanoid
		local weld = Instance.new("Weld")
		weld.Part0 = character.Head
		weld.Part1 = holderpart
		weld.C1 = CFrame.new(0,-1,0)
		weld.Parent = holderpart
		holderpart.CFrame = character.Head.CFrame
		local loadanimation = humanoid:LoadAnimation(animation)
		loadanimation:Play()
		local bodyforce = Instance.new("BodyForce", balloon.Sphere)
		bodyforce.Force = Vector3.new(0,1000,0)
		wait(timeuntilpop.Value)
		weld:Destroy()
		loadanimation:Stop()
		bodyforce:Destroy()
		isonb = false
	end
end)

Isonb is supposed to be the debounce. I tried adding another debounce, but that didn’t work. What do I do from here?

1 Like

's probably because you declared your debounce variable inside the Touched event instead of outside, so the debounce is local to that function and not the Touched event overall. Just move it out of the function to the top of your script and try again.

3 Likes

you are making a new variable of isnob as false each time the part is touched. Move it out of the touched function.

1 Like