Why isn't this rain script working properly?

I edited my reply. Please see the changes.

1 Like

The code itself is fine, works as expected in studio. It must be some other underlying behavior. But the best way to debug a loop is to check your loop invariant on every iteration to ensure that it works as expected. So try printing out rainspawned to try and find the context of why that if statement might be failing.

@wevetments I did your change. It does show that it got to 50, but it didn’t stop.

did u try mine? (30 characters)

If this is the entire script and it prints the statement at the bottom of the script, that means the loop was broken by the if statement and it should stop spawning, meaning the code works as intended

My hypothesis is that you have multiple scripts doing the same thing, but I could be wrong. Do you mind sending a file of your place?

1 Like

That is really weird. It does seem to stop on my studio. It’s surely something else that’s the problem then.

@nuttela_for1me Yes, it didn’t work, though.

Please try this, if this doesn’t work I estimate it may be something to do with your end

local rainspawned = 3

while true do
	if rainspawned >= 100 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.Transparency = 0.5
	Rain.Anchored = false
end

print("No More Rain")

No. I only have 1 script trying to break that loop. The script spawns the part and everything.

@MistakenScopeZ The print at the very bottom works, but the rain just keeps on going.

I feel like its definitely a problem on your end. I tested it and it works flawlessly.

1 Like

Perhaps you should try restarting studio. The code we’re suggesting to you works fine on our end.

Ok. I’ll try restarting it. Also, this is the video:

yes this script work for me too

1 Like

Oh, my gosh. I still restarted studio and it still doesn’t work. The print is still getting outputted, but the parts that are falling are not stopping.

Do you mind sending a place file of your game so we can look into it ourselves?

1 Like

Practicing Code.rbxl (30.6 KB)

You have another script creating the parts in an infinite while loop, which is the Instancing script. If you disable that, everything should be fine. I knew it… so my hypothesis was correct.

image

3 Likes

I see whats wrong… u got ur script named “Instancing” which generates block for ever, so the block actaully stops but u cant see the difference because of the other blocks spawning by the other script

Oh, my. I should’ve known that. He used the same script, but erased what he had in it. I should changed the name. Ok, let me change the name and I’ll see.