mouse.Button1Down fires 2 times

So I’m trying to make a flashlight with mouse.Button1Down but it wont work after using it 3 times. others say it may be in a loop or other but I have nothing on it,
It fires 2 times when you click on it and then wait some seconds.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Char = player.Character
local Arms = game.Workspace.Camera:WaitForChild("Arms")
local Server = game.ReplicatedStorage.Guns.FPS

local FL = false

mouse.Button1Down:Connect(function()
		if player.PlayerGui.Inventory.BG.Selected.Value then
			if player.PlayerGui.Inventory.BG.Selected.Value.Name == "Flashlight" then
				if game.Workspace.Camera.Arms.Items:FindFirstChild("Flashlight") then
					if game.Workspace.Camera.Arms.Items.Flashlight.Handle.Enabled.Value == true then
						print("Off")
						game.Workspace.Camera.Arms.Items.Flashlight.Handle.Enabled.Value = false
						script.On:Play()	
						game.Workspace.Camera.Arms.Items.Flashlight.Emitter.SpotLight.Enabled = false
						game.Workspace.Camera.Arms.Items.Flashlight.Emitter.Beam.Enabled = false
					elseif game.Workspace.Camera.Arms.Items.Flashlight.Handle.Enabled.Value == false then
						print("On")
						game.Workspace.Camera.Arms.Items.Flashlight.Handle.Enabled.Value = true
						script.On:Play()	
						game.Workspace.Camera.Arms.Items.Flashlight.Emitter.SpotLight.Enabled = true
						game.Workspace.Camera.Arms.Items.Flashlight.Emitter.Beam.Enabled = true
					end
				end
			end
		end
end)

first it prints On then Off but later on it fires 2 times and prints Off and On on the same time.
I tried doing UserInputService and that didnt work too I tried doing Up instead Down didnt work too, I hope theres any other way to fix this.

If it fires two times that means there are two button one down connections.

By any chance do you have multiple flash light tools in your backpack? LocalScript | Roblox Creator Documentation will still run in the back pack even if unequipped so if you have two flash lights you will have two mouse button one down connections.

You can solve this by adding a variable that tells if tool is equipped or not via the tool.Equipped event.

Im using my own inventory system when I have 2 items in my inventory the flashlight works normaly fine

Are you sure you don’t have any mouse problems etc.?

My friend has the bug too ingame and other people too

1 Like

Then do you have multiple copies of the same local script? Not enough info on what exactly you did with user input services and all that.

Otherwise just try stuffing a Debounce Patterns | Roblox Creator Documentation in there to prevent the flashlight from switching on and off rapidly and see what you notice.

I already tried using debounce but I can try again

Debounce didnt work. even with wait(1)