Why isn't this rain script working properly?

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!")

robloxapp-20200529-1539326.wmv (786.7 KB)

Game File;
Practicing Code.rbxl (30.6 KB)

2 Likes

Do you receive any errors? We need to know that

No. It does print out the print statement

Then your script works. It reached it because one of your lines did break.

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

1 Like

It did work, but the rain just keeps on going.

What are trying to do? Please be specific

To the work space. It’s just like the tutorial. Everything is done just like the tutorial.

Can you give us the video that you are doing the tutorial from?

Does the tutorial have a copy and paste of the script?

I will record a video to show what is going on.

I know what’s going on. I need to know what you are trying to acheive.

Next time please indent, it would really help us figure out the problem.

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.

1 Like

I did. I’m not sure why it didn’t work though.

use

             '''
 

     '''

to properly format the code.

I know why, put your if statement at the end

Ok. I’ll see if this will make it function properly now.

You can place it anywhere in the loop and it will still stop it once it reaches 50+ I don’t think that will solve the issue.