New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do I stop this While True Do loop?

Asked by 3 months ago

There are the proper variables in place btw

Anyways, this script is supposed to make a block strobe and stuff, but I can't get it to stop. I try to break the loop but it does nothing and keep strobing. What am I missing here?

function strobe()
    s:Play()
    local parts = a:GetChildren()
    for i,v in pairs(parts) do
        if v.name == "Strobe" then
            spawn(function(f)
                while true do --Setting up a loop to cycle through 
                    v.Material = "Neon"
                    v.PointLight.Brightness = v.PointLight.Brightness == 0 and 5 or 0;
                    wait(0.03)
                        if t.Screen.SurfaceGui.MainFrame.GrayThing.ImageLabel.ImageButtonOff.MouseButton1Down == true then
                            break
                        end
                    end

            end)
       end   
   end
end

t.Screen.SurfaceGui.MainFrame.GrayThing.ImageLabel.ImageButtonOn.MouseButton1Down:Connect(function()
    strobe()
end)

c.MouseClick:Connect(function(clicker) --Linking a function to the click of the handle
    strobe()
end)

Thanks!

0
.MouseButton1Down isnt a boolean, its an event theking48989987 2067 — 3mo
0
But how would I stop the loop and return the blocks to being static? MustangHeart 54 — 3mo

1 answer

Log in to vote
1
Answered by
sO_Ov 150
3 months ago
Edited 3 months ago
--You can stop while true do making a variable true and changing to false
local loop = true

while loop do
    wait()
    print("Hello")
    loop = false
end

--Example using click
script.Parent.MouseButton1Click:connect(function()
   loop = false
end)
0
i dont see the point of setting loop to false in the actual while loop itself, it just stops it after one iteration theking48989987 2067 — 3mo
0
lol totally forgot that was a feature. Thanks dude! MustangHeart 54 — 3mo
0
and place the event above the loop, anything under an infinite loop wont run theking48989987 2067 — 3mo
Ad

Answer this question