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

How Can I Break This Loop? [SLOVED]

Asked by 9 years ago

Hello!

I need your help to find how to break this loop in line 3 when I release mouse button:

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        while mouse.Button1Down do
            wait()
            if mouse.Target.Name == "DrawBoard" then
                    local instspr = Instance.new("Part")
                instspr.Parent = mouse.Target
                instspr.CFrame = CFrame.new(mouse.Hit.p) * CFrame.new(0, 0.1, 0)
                instspr.Anchored = true
                instspr.CanCollide = false
                instspr.BrickColor = BrickColor.new("Institutional white")
                instspr.Name = "DrawPix"
                instspr.FormFactor = Enum.FormFactor.Custom
                instspr.Size = Vector3.new(0.2, 0.2, 0.2)
                instspr.BottomSurface = Enum.SurfaceType.Smooth
                instspr.TopSurface = Enum.SurfaceType.Smooth
            end
        end
    end)
end)

1 answer

Log in to vote
4
Answered by
SirNoobly 165
9 years ago

A debounce.

mouse.Button1Down:connect(function()
    down = true --Setting down to true before the loop starts
    while down do -- While down is true it will loop
    --stuff
    end
end)

mouse.Button1Up:connect(function()
    down = false --When button it released it sets down to false thus breaking the loop
end)
0
Lol thanks. vincius0000 0 — 9y
0
Works1 vincius0000 0 — 9y
0
Wouldn't you want to put the while loop outside the click event? Perci1 4988 — 9y
0
Yeah if you put it in a function then run that function every time the click event happens. SirNoobly 165 — 9y
Ad

Answer this question