Heya.
As the title says, I’ve made a flamethrower although it randomly decides to release the mouse and stops the flames from spewing out.
local UIS = game:GetService("UserInputService")
local Ticket = 0 --Using a ticket service so it won't be confused by normal clicks I guess.
local timeHeld = 0.2
local isHolding = false
function MouseHeld()
isHolding = true
while isHolding do
print("Fire!")
Tool.Flamethrower.Attachment.Flames.Enabled = true
Tool.Flamethrower.Attachment.Smoke.Enabled = true
task.wait()
end
end
function MouseReleased()
if not isHolding then return end
isHolding = false
print("Done :)")
Tool.Flamethrower.Attachment.Flames.Enabled = false
Tool.Flamethrower.Attachment.Smoke.Enabled = false
end
UIS.InputBegan:Connect(function(i,gp)
if gp then return end
if i.UserInputType == Enum.UserInputType.MouseButton1 then
Ticket = Ticket + 1
local CurrentTicket = Ticket
if timeHeld > 0 then
delay(timeHeld, function()
if Ticket == CurrentTicket then
MouseHeld()
end
end)
else
MouseHeld()
end
end
end)
UIS.InputEnded:Connect(function(i,gp)
if gp then return end
Ticket = Ticket + 1
MouseReleased()
end)