Accidentally made my gun a 2-round burst instead of fully automatic

  1. What do you want to achieve? I want to know how to turn my gun fully automatic instead of a burst.

  2. What is the issue? I don’t know how to change my gun to full auto.

  3. What solutions have you tried so far? I’ve tried tinkering around and searching.

My client side script:
image_2021-05-29_174825

Couldn’t you just loop it until mouse.Button1up?

1 Like

How?

Sorry, I’m still very new to scripting

try doing

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
Fire = true
repeat
script.Parent.Fire:FireServer(Mouse.Hit.p)
wait()
until Mouse.Button1Up
Fire = false
end)

This tutorial has the most simplified version from what I have seen so far of how to achieve a fully automatic gun in one code block.

To explain every frame (HeartBeat) it checks if the mouse is held down and if the gun can fire again via a debounce. If the gun can fire then it will fire one bullet via the function MainModule.cast() then wait() until it can fire again.

Keep in mind it’s not the best method as wait() is capped to 1/30 seconds so it will have a problem with really fast firing guns, the best automatic guns will use an accumulator to make it frame independent which is a bit more complex so just keep this in mind.

Tried it, doesn’t work.

Am I supposed to put anything in wait()?

no but I think the problem is that you’re using mouse instead of userinputservice so

repeat
script.Parent.Fire:FireServer(Mouse.Hit.p)
wait()
until Mouse.Button1Up

doesnt work.

I would try using this

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

UserInputService.InputBegan:Connect(function(Input, GP)
if GP then
return
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
Fire = true
repeat
script.Parent.Fire:FireServer(Mouse.Hit.p)
wait()
until not UserInputService:IsKeyDown(Enum.UserInputType.MouseButton1)
Fire = false
end
end)

im not sure if it works

Doesn’t work either, got a bunch of “Players.RawBread.Backpack.M4A1.Client:12: attempt to index nil with ‘Hit’”

Oh sorry, I removed the mouse variable let me add it back

check the edit now it should work

Turned semi-automatic with the error message “Unable to cast token to token”

I’m supposed to put this into the client script right?

yes it is meant to be client sided but I believe I didnt do it correct

until not UserInputService:IsKeyDown(Enum.UserInputType.MouseButton1)

is probably not a valid ‘Key’