Loop Debounce help

Im trying to make a double jump script, and a effect showing when you can double jump. But when that effect is done and you are unable to double jump and you jump it plays the effect and does not double jump the player? Can someone please help me?

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")

local jumpUsage = 1

local uis = game:GetService("UserInputService")
db = true

uis.InputBegan:Connect(function(key, gp)
	if key.KeyCode == Enum.KeyCode.Space and not gp then
		
		if  game.Players.LocalPlayer.folder.Doublejump.Value == false then
			return
		end
		print(game.Players.LocalPlayer.folder.Doublejump.Value)
		print("ass")
		
		if humanoidRootPart and humanoid then
			if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
				if jumpUsage >= 1 then
					jumpUsage -= 1
					
					humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
					humanoid.StateChanged:Connect(function(old, new)
						
						game.ReplicatedStorage.Abilites.Jump2:FireServer(game.Players.LocalPlayer)
						
						local value = 0
						
						if db == true then 
							db = false
							
							local idk = game.ReplicatedStorage.Poof:Clone()
							idk.Position = char.HumanoidRootPart.Position
							idk.Parent = workspace
							task.wait(0.5)
							idk:Destroy()
							
							while db == false do
								wait(0.1)
								game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = true
								value += 0.1
								game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position += UDim2.new(0,0,0.01,0)
								game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  true
								local newvalue =  math.round(value / 100) * 100
								game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Text = string.format("%0.1f", 10 - value)
								if game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position.Y.Scale >= 1   then
									game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = false
									game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position = UDim2.new(0,0,0,0)
									game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  false
									db = true
									jumpUsage = 1
									return
								end
							end	
								
								
						

						else return end
					end)
				end
			end
		end
	end
end)
1 Like

bump