How would you make a burst of a gun?

Hello! I researched this topic on youtube and devforum, and looked for mouse and tool events on dev hub, but no success. All I want to know is how I can make the burst myself

1 Like

Please specify what you are trying to say, as this is currently too hard to understand. Follow the template Roblox provides, If needed.

1 Like

Like you know in arsenal the G-18 has a burst? (Bullets fire when you hold down the left mouse button) That’s what I’m trying to achieve.

What solutions have you tried so far? What part of the problem are you struggling with? Do you have a working semi-automatic gun already?

1 Like

I’m looking for an event or something that fires when the mouse is down, I tried Mouse1Down, but it only shoots one bullet

While the mouse is held down, continue to fire up till N bullets.

I think a simple way to do this is a repeat until loop or a while do loop.

local UserInputService = game:GetService("UserInputService")

local Shots = 0
local BurstShotsAllowed = 4

local function Fire()
    --// Fire a bullet bla bla bla

    Shots = Shots + 1
end

repeat
    local MouseUp = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
    Fire()
    wait(FireRate)
until (Shots == BurstShotsAllowed) or MouseUp

Shots = 0
2 Likes

Its not working for some reason…

local UIS = game:GetService("UserInputService")
local BODY_DAMAGE = 20
local HEADSHOT = 40
local CLIP = script.Parent.Ammo
local MAX_BULLETS = script.Parent.Max
local SHOOTY_PART = script.Parent.TopBarrel
local HandleOfGun = script.Parent.Handle
local Part_1 = script.Parent.MeshPart
local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()
local Reload = false
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local shot = false


script.Parent.Equipped:Connect(function()
	local Gui = script.Parent.G18:Clone()
	if Gui.Parent ~= Player.PlayerGui then
		Gui.Parent = Player.PlayerGui
	end
end)

script.Parent.Unequipped:Connect(function()
	local Gui = Player.PlayerGui.G18
	Gui:Destroy()
end)

function Fire()
CLIP.Value = CLIP.Value - 1
if CLIP.Value <= 0 then
   print("reloadtime")
   Reload = true
   script.Reload:Play()	
   wait(2)
   CLIP.Value = 8
   MAX_BULLETS.Value = MAX_BULLETS.Value - CLIP.Value
   if MAX_BULLETS.Value < 0 then
	  script.Disabled = true	
   end
   Reload = false
   print("m")
else
if Reload == false and shot == false then
   shot = true
   local MousePos = mouse.Hit.p
   game.ReplicatedStorage.G18:FireServer(Character, HEADSHOT, BODY_DAMAGE, SHOOTY_PART, MousePos, HandleOfGun, Part_1)
   shot = false
   end		
end
end

repeat
	local MouseUp = UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
	Fire()
	wait(3)
until (CLIP.Value > 0) or MouseUp

No errors

local fire = false

function shoot()
    if fire == true then
        --shooting code
    end
end

mouse.Button1Down:Connect(function()
    fire = true
end)
mouse.Button1Up:Connect(function()
    fire = false
end)
game:GetService("RunService").RenderStepped:Connect(shoot)

I already tried mouse.Button1Down, sorry

Are you doing this code in a LocalScript?
(Also I edited me code to make it shoot when the button is down)