Need help with UserInputService

Hello,
I am making a simulator game, and I need help with an issue I had for almost a week now. The point of the game is like any other simulator to click… by cicking you get ‘Zaps’ and by standing on the sell place your zaps get converted into 'Coins
I have a Local Script in starter player scripts
And I have sell place. The problem is, everything works until sometimes after you sell your(zaps) the script breaks and you can’t click to get more zaps, here is the Local Script.
I tried removing the debounce but then the player can use auto clicker which isnt the best option. Thank you! (btw my sell script basically gets the players leaderstats and adds the zaps value to the coins value and sets the zaps value to 0)

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local debounce = false


UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
	 
	if gameProcessedEvent == true then
		print("click")
		else
			
			if not debounce then
				debounce = true
				
			if player.leaderstats.Zaps.Value == player.BackpackShop.BackpackV.Value then
				player.PlayerGui.FullBag.BackFrame.Main:TweenPosition(UDim2.new(0.4, 0, 0.35, 0), "Out", "Elastic", .7)
				wait(.9)
				player.PlayerGui.FullBag.BackFrame.Main.InfBag:TweenPosition(UDim2.new(0, 0,1.061, 0), "Out", "Bounce", .2)
				else
					
					game:GetService("ReplicatedStorage").GiveZaps:InvokeServer()
					wait(.7)--wait for debounce :D
					debounce = false
					end
				end
			end
		end
	end)

You didn’t set the debounce to false under the condition that the backpack is full

			if not debounce then
				debounce = true
				
			if player.leaderstats.Zaps.Value == player.BackpackShop.BackpackV.Value then
				player.PlayerGui.FullBag.BackFrame.Main:TweenPosition(UDim2.new(0.4, 0, 0.35, 0), "Out", "Elastic", .7)
				wait(.9)
				player.PlayerGui.FullBag.BackFrame.Main.InfBag:TweenPosition(UDim2.new(0, 0,1.061, 0), "Out", "Bounce", .2)
				else
					
					game:GetService("ReplicatedStorage").GiveZaps:InvokeServer()
					wait(.7)--wait for debounce :D
					debounce = false
					end

See how you reset debounce only after the “else” meaning that after you’re backpack is full you are stuck with debounce on true

1 Like