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

How i can fix this automatic rifle script?

Asked by 4 years ago

Hi guys!

Sorry for bad english.. i have write this code ->

    UIS.InputBegan:connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            if Equipado == true then
                if Recarregando == false then
                    Atirando = true
                    spawn(function()
                        while Atirando == true do
                        wait()
                            if Recarregando == false then
                                if Bala > 0 then
                                    Atacar()
                                    Bala = Bala - 1
                                    refresh(Bala)
                                elseif Recarregando == false then
                                    Recarregando = true
                                    script.Parent.Handle.Reload:Play()
                                    refresh("R")
                                    Atirando = false
                                    wait(2)
                                    Bala = LimitBala
                                    refresh(Bala)
                                    Recarregando = false
                                end
                            end 
                        end
                    end)
                end
            end
        end
    end)
    UIS.InputEnded:connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            if Equipado == true then
                Atirando = false
            end
        end
    end)

This script work correctly, but if i do a double-click, this script broke (in short, the script is performed 2 times and not 1).

Who can help me?

0
Obviusly, ONLY if is a fast double-click. If is a slow double click all works good GuerraReturns 122 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Fixed:

UIS.InputBegan:Connect(function(Input)

    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
       keydown = true
    end
end)

UIS.InputEnded:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then
        keydown = false
    end
end)

while true do
    wait(0.03)
    if keydown then
        if Equipado == true then
            if Recarregando == false then
                Atirando = true
                if Bala > 0 then
                    Atacar()
                    Bala = Bala - 1
                    refresh(Bala)
                elseif Recarregando == false then
                    Recarregando = true
                    script.Parent.Handle.Reload:Play()
                    refresh("R")
                    Atirando = false
                    wait(2)
                    Bala = LimitBala
                    refresh(Bala)
                    Recarregando = false
                end
            end
        end
    end
end
0
change with while wait() do, is better GuerraReturns 122 — 4y
Ad

Answer this question