Alright so I have this script that starts when a bool changes and I want it to loop if that bool value is true, How?? This is what I have so far
while true do c = script.Parent.LightUp:GetChildren() if script.Parent.ON.Value == true then for i = 1, #c do if math.random() > 0.5 then c[i].BillboardGui.ImageLabel.Visible = true else c[i].BillboardGui.ImageLabel.Visible = false end end elseif script.Parent.ON.Value == false then end wait(0.1) end
Firstly, you should learn how to tab it correctly. It will greatly help your scripting. An example would be this:
while true do c = script.Parent.LightUp:GetChildren() if script.Parent.ON.Value == true then for i = 1, #c do if math.random() > 0.5 then c[i].BillboardGui.ImageLabel.Visible = true else c[i].BillboardGui.ImageLabel.Visible = false end end elseif script.Parent.ON.Value == false then wait(.1) -- You also put the end for the entire branching of the if statement before wait causing line 11 and 12 to be utterly useless and causing an error. end end
Next off is how to do this correctly. As of right now, "while true do" is basically a loop that will continue on forever. This is because the "while" loop checks if the condition is true or not. "While true" is a means of repeating the script over and over without it stopping, thus nothing will happen after it. This will NOT check boolean values. However, you can still use the "while" loop. Only with a bit of editing. Instead of checking if true is possible, you can check if the variable is true or not.
while script.Parent.ON.Value == true do
What this will do is check if the value of the boolean value that you have under your script parent. In order to compensate and correct this entire script, you would remove the if's and elseif's that deal with the on value. Thus delete lines 3, 11, 12, and 13. With this being the end result:
while script.Parent.ON.Value == true do c = script.Parent.LightUp:GetChildren() for i = 1, #c do if math.random() > 0.5 then c[i].BillboardGui.ImageLabel.Visible = true else c[i].BillboardGui.ImageLabel.Visible = false end end end
Shame on you for skipping to the end if you did so, because this post will help your scripting knowledge as will as help you find your answer!