What is the most efficient way of making an automatic weapon?

relatively simple. just curious what the best method of doing it is

here’s my idea:

repeat
   print("fire")
   fire:FireServer()
   task.wait(cooldown) -- 0.1s
until not uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

what ends up happening, though, is that it is very inconsistent on its firing. i assume it is because i try to send a remote to the server but its still on cooldown so it just ignores it.

i used a RemoteFunction to fix this, but im just curious whether thats the best method.

thanks for reading :wink:

in the end, i think the best method is this:

-- in an InputBegan function
fire:FireServer(true)

-- in an InputEnded function
fire:FireServer(false)

true for when you want to start firing and false for when you want it to stop.
hope this helps :tongue:

The way I usually handle this is having an InputBegan and InputEnded and under the Began variable I would have a

UIS.InputBegan:Connect(function(input)
    if input == Enum.UserInputType.MouseButton1 then
       IsHoldingMouse = true
    end
end)

UIS.InputEnded:Connect(function(input)
    if input == Enum.UserInputType.MouseButton1 then
       IsHoldingMouse = true
    end
end)

and then in a repeat loop or render stepped function have a debounce variable tied to the firerate of the weapon and fire the remote event every firerate as long as the IsHoldingMouse == true

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.