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

Everytime I fire my gun and stop it shoots faster?

Asked by
Galicate 106
6 years ago

Everytime I shoot my gun, it fires at normal speed. But when I let go then fire again it shoots faster. If I continue this I can get to shooting an entire clip in half a second. Help?

-----------Settings Variables----------
local FireRate = 0.1
local Damage = math.random(30,70)
local ReloadTimes = 2
---------------------------------------
local Player = game.Players.LocalPlayer
local mouse_hold = true
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
local tool = script.Parent
local action_fire = false
local stop_fire = false
local player = game:GetService("Players").LocalPlayer
local Ammo = script.Parent:WaitForChild("Ammo")
tool.Equipped:connect(function(mouse)
print("Tool equipped!")
holdanim = player.Character.Humanoid:LoadAnimation(script.Parent.HoldAnim)
reloadanim = player.Character.Humanoid:LoadAnimation(script.Parent.ReloadAnim)

 mouse.Button1Down:connect(function(startfire)
        if Ammo.Value >= 1 and action_fire == false then
    action_fire = true
    stop_fire = false
        while true do
            wait()
            if Ammo.Value >= 1 and stop_fire == false then
                action_fire = true
            wait(FireRate)
        print("Mouse pressed!")
        Ammo.Value = Ammo.Value - 1
        print(Ammo.Value)
        script.Parent.Handle.Fire:Play()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Gold")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.99
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Main.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)


        game:GetService("Debris"):AddItem(beam, 0.1)

        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(Damage)

            end
end
end
        end
end
        end)
end)

local Player = game.Players.LocalPlayer
local action_reload = false
Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "r") and Ammo.Value < 18 and action_reload == false then
        action_reload = true
        script.Parent.Handle.Reload:Play()
        reloadanim.Looped = false
        reloadanim:Play()
        wait(ReloadTimes)
        Ammo.Value = 18
        print(Ammo.Value)
        action_reload = false
    end
end)

script.Parent.Equipped:connect(function(Mouse)
    Mouse.Button1Up:connect(function(stopfire)
        action_fire = false
        stop_fire = true    
        print("Stopped Firing")
    end)
end)
0
Friend me on Roblox. I will discuss what is wrong. User#19524 175 — 6y

Answer this question