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.