I’m following a YouTube tutorial by a YouTuber known as TheDevKing. The tutorial explains and shows how to break a loop. More specifically, a while loop. He made an example of making rainfall from the sky, and after a while, the loop will break. However, his script worked, but mine didn’t. Mine is a replica of his, and I’m not sure why it isn’t working. Also, the print statement does get printed. Down below is the script:
local rainspawned = 0
while true do
if rainspawned >= 50 then
break
end
rainspawned = rainspawned + 1
wait()
local Rain = Instance.new("Part",game.Workspace)
Rain.Size = Vector3.new(0.5,2,0.5)
Rain.Position = Vector3.new(0,15,0)
Rain.Anchored = false
Rain.Transparency = 0.5
end
print("The Loop is finished!")
What type of script is it? Where did you parent the script? Do you have any errors in the output from this script? You aren’t really providing us with much information for us to help you
I should also say that we have codeblocks to put code in and actually indent your code so it looks better. I’d also like to say that shouldn’t use the 2nd argument of Instance.new because of issues with performance, and there is a PSA about it – initialise the instance (set its properties) then set its parent last
I’m just following the tutorial to practice coding. I’m not making a game or anything. You could say there is an achievement because I’m trying to break the loop.
Please format your code correctly next time. We have available guides on how to do so.
local rainspawned = 0
while true do
if rainspawned >= 50 then break end
rainspawned = rainspawned + 1
local Rain = Instance.new(“Part”,game.Workspace)
Rain.Size = Vector3.new(0.5,2,0.5)
Rain.Position = Vector3.new(0,15,0)
Rain.Anchored = false
Rain.Transparency = 0.5
wait()
end
print("The loop is finished")
Your code is logically correct, aside from the fact is executes instantly. I’m guessing the issue is somewhere else and this is not the whole script.