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

My script doesn't stop and I need help fixing that?

Asked by
JoneXI 51
4 years ago

Hello, I have a GUI basically when I click on a button my color cycle starts playing, after I click the back button it doesn't stop... 27-35th lines.

Here's the script:

local btn1 = script.Parent.btn1
local btn2 = script.Parent.btn2
local btn3 = script.Parent.btn3
local btn4 = script.Parent.btn4
local btn5 = script.Parent.btn5
local btn6 = script.Parent.btn6
local btn7 = script.Parent.btn7
local btn8 = script.Parent.btn8
local hack = true
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local folder = ReplicatedStorage.HackEvents
local hacking1 = folder.Hacking1
local hacking2 = folder.Hacking2

local btnTable = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8}
function cycle()
while true do
for i=1,#btnTable do
    print("Hack happening")
         btnTable[i].BackgroundColor3 = Color3.fromRGB(0, 255, 0)
        wait(1)
        btnTable[i].BackgroundColor3 = Color3.fromRGB(255, 0, 0)    
end
end
end

hacking2.OnInvoke = function()
    hack = false
end

hacking1.OnInvoke = function()
    while hack == true do
        cycle()
    end
end
0
Try putting the .OnInvoke statements before the while loop. y3_th 176 — 4y

Answer this question