Debounce not working

local OneEggOpenUi = script.Parent
local EggPrice = 100
local UIS = game:GetService("UserInputService")
local BasicEggHatch = game.Workspace.BasicEggHatch
local plr = game.Players.LocalPlayer

local db = false
OneEggOpenUi.MouseButton1Down:Connect(function() 
	-- make egg open
	if not db then
		db = true
	
	
	if plr.leaderstats.Coins.Value >=100 then
		plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - 100 

		BasicEggHatch.Position = Vector3.new(728.6, 6.3, 37.9)
	
			db = false
		end
		
			while true do
		
			
			wait(0.2)
			BasicEggHatch.Orientation += Vector3.new(15,15,15)
			wait(0.2)
			BasicEggHatch.Orientation -= Vector3.new(15,15,15)
			wait()
		end
		
		
	else 
		print("Player Can't Afford Basic Egg")
		local ErrorUIHandler = game.Players.LocalPlayer.PlayerGui.ErrorUIHandler
		ErrorUIHandler.Enabled = true 
		local ErrorSound= ErrorUIHandler.ErrorSound
		ErrorSound:Play()
		wait(2)
		ErrorUIHandler.Enabled = false
		ErrorSound:Stop()
		-- make a Ui
		
		
		end
end)

my debounce is not working I can buy the egg multiple times

You have a while loop and never broke the while loop- the script will forever repeat the while loop.

2 Likes