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

Full auto gun; While loop not breaking. I think? [SOVLED]

Asked by 5 years ago
Edited 5 years ago

Ive been trying to make a gun script for the first time. I am trying to get full auto working but if you spam click it starts multiple while loops and so then next time you hold down your mouse button it shoots a ton of times.

So I am having problems breaking the while loop.

Heres the 2 code segments I have tried.

Tool.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        Pressed = true        
        while Pressed == true do
            GunEvent:FireServer(Tool.Barrel.CFrame.Position, Mouse.Hit.Position)
            wait(1)
            break
        end        
    end)

    Mouse.Button1Up:Connect(function()
        Pressed = false
    end)
end)

Heres the second

Tool.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        Pressed = true        
        while Pressed == true do
            GunEvent:FireServer(Tool.Barrel.CFrame.Position, Mouse.Hit.Position)
            if Pressed == false then
                break
            end

            wait(1)
        end        
    end)

    Mouse.Button1Up:Connect(function()
        Pressed = false
    end)
end)

Neither of them work, but I feel like Im closer on the first one. Does anyone have any ideas? What am I doing wrong?

Thank you for your time :)

Answer this question