Hey eveyone, sorry for the dumb question but i am having some difficulties right now with my code, I want to have a loop break once the boolean value updates, here is the script:
local MenuOver = script.Parent:WaitForChild("MenuOver") MenuOver.Value = false print("Menu Over is ", MenuOver.Value) -- This prints successfully
PlayBtn.MouseButton1Click:Connect(function() MenuOver.Value = true SlideInSide:Play() print("Menu Over is ", MenuOver.Value) -- This also prints correctly end)
Here is the issue here, i want the loop here to break once the value changes, how do i do that?
while MenuOver.Value == false do Cam.CFrame = CamPoints:FindFirstChild("1").CFrame TweenCameraPos(CamPoints:FindFirstChild("2"), 4) wait(4) Cam.CFrame = CamPoints:FindFirstChild("3").CFrame TweenCameraPos(CamPoints:FindFirstChild("4"), 4) wait(4) Cam.CFrame = CamPoints:FindFirstChild("5").CFrame TweenCameraPos(CamPoints:FindFirstChild("6"), 4) wait(4) Cam.CFrame = CamPoints:FindFirstChild("7").CFrame TweenCameraPos(CamPoints:FindFirstChild("8"), 4) wait(4) Cam.CFrame = CamPoints:FindFirstChild("9").CFrame TweenCameraPos(CamPoints:FindFirstChild("10"), 4) wait(4) if MenuOver.Value == true then Cam.CameraType = Enum.CameraType.Follow Cam.FieldOfView = 70 break end end
Thanks!
Well, the first thing you'd want to do would to be not to repeat your code more than necessary, but after that, you'd just want to check in between every step whether it met the conditions. Also, you might want to have some conditions in place in case FindFirstChild doesn't find what it's looking for.
while MenuOver.Value == false do for i=1,10 do if MenuOver.Value == true then --Lets break out of the loop here break end if i % 2 == 1 then --Odd number, update the CFrame Cam.CFrame = CamPoints:FindFirstChild(tostring(i)).CFrame else --Even number, tween the camera TweenCameraPos(CamPoints:FindFirstChild(tostring(i)), 4) wait(4) end end end Cam.CameraType = Enum.CameraType.Follow Cam.FieldOfView = 70