Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my gun fire in full auto twice if I press down twice?

Asked by
kofe_i 4
6 years ago

My username is Yeeterbo_i and I am a beginner scripter. Recently, I have been trying to make my own non raycast gun for future games. However, I just ran into a problem while trying to make it full auto. If I click twice before my gun fires again, my gun instead of going pew (wait 0.1) pew (wait 0.1) pew, it goes like this: pew pew (wait 0.1) pew pew (wait 0.1) pew pew.

If you need the script for my gun, its down here.

-- This is an extremely simple non-raycasting pistol made by Yeeterbo_i. It is basically a fancy damage brick teleporter.
--Variables
input_service = game:GetService("UserInputService")
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local ammo = 12
local mag = 12
local CanReload = true
local reload = false
local Firing = false
tool.Equipped:Connect(function(mouse)


 mouse.Button1Down:Connect(function()
    Firing = true
    while ammo > 0 and reload == false and Firing == true  do --Checks for ammo and if player is currently reloading

        --Visual effects
        tool.FireDecalHolder.FireDecal1.Transparency = 0
        tool.FireDecalHolder.FireDecal2.Transparency = 0

    tool.SlideBack.Transparency = 0
        tool.Slide.Transparency = 1
        --Audio effect
        tool.FireSound.TimePosition = 0
        tool.FireSound.Playing = true

        --Creating damage brick
    local oof = game.Workspace.Oofpart:Clone()
        oof.BrickColor = BrickColor.Black()
        oof.Size = Vector3.new(0.7,0.7,0.7)
        oof.Position = mouse.Hit.p
        oof.Transparency = 0
        oof.Anchored = true
        oof.CanCollide = false
        oof.Parent = workspace

    game:GetService("Debris"):AddItem(oof, 0.001)--Removing block
    ammo = ammo - 1 --Removing ammo from mag
    wait(0.05)

    --Removing visual effects
    tool.FireDecalHolder.FireDecal1.Transparency = 1
        tool.FireDecalHolder.FireDecal2.Transparency = 1

    tool.SlideBack.Transparency = 1
        tool.Slide.Transparency = 0
        wait(0.1)--ROF
    end
if ammo < 1 then
    tool.EmptySound.TimePosition = 0
    tool.EmptySound.Playing = true
        end
    end)
end)
mouse.Button1Up:Connect(function()
    Firing = false
end)
 function PressedR(key)
    if key == "r" and CanReload == true then
    CanReload = false
    script.Parent.ReloadSound.Playing = true
            print("oof")
        reload = true
        wait(1.5)
        reload = false
        ammo = mag
    CanReload = true
    end
end

mouse.KeyDown:Connect(PressedR)
0
KeyDown is deprecated, do not use it in new work. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

It happens because every time you click with your mouse you set Firing to true and then in the next line you check if it's true which means it will be true every time you click.

Simple fix would just be to check if it's false.

Ad

Answer this question