Wave doesn't stop after for-loop ended (in Survival game)

Hello devs,

I am creating a game with different waves. The first wave is that meteors are falling down and you have to avoid them otherwise you die. I created a for-loop which should spawn 15 meteors on a random position from a folder.

That works fine, the meteors are spawning. But the problem is that they don’t stop after 15 have spawned. I tried using the print function to check the problem. But that print function stops with 15 even though there are still meteors getting spawned.

Could someone help me with the problem because I have tried different things, but I cannot find the problem.

My waves script:

local WavesFolder = game.ReplicatedStorage.Waves
local Minutes = game.StarterGui.Timer.Minutes
local Seconds = game.StarterGui.Timer.Seconds

--Waves
local Meteor = game.ServerStorage.Meteor --The meteor
local HitParts = WavesFolder.HitParts --Killbricks for the 2nd wave
local VulcanoWave = WavesFolder.Vulcano --This includes a vulcano (haven't used it yet) and a folder with random positions for the meteors
local MeteorFolder = VulcanoWave.Meteors:GetChildren()


local function ThrowMeteors()

		for i = 1,15,1 do
			local randomPosition = MeteorFolder[math.random(1, #MeteorFolder)]
			local MeteorClone = Meteor:Clone()
			MeteorClone.Parent = workspace
			MeteorClone.Position = randomPosition.Position
			print("Meteor number "..i) --this stops at number 15
			wait(1)
		end

end

local function SpawnHitParts()

		for i = 1,15,1 do
			local randomPart = HitParts[math.random(1, #HitParts)]
			local partClone = randomPart:Clone()
			partClone.Parent = workspace
			wait(5)
			partClone.Destroy()
			wait(5)
		end

end

ThrowMeteors()
wait(30)
SpawnHitParts()

Video:

What does the function SpawnHitParts() do?

That function should add suddenly some big red parts to the game, you don’t know where. When you are at the wrong place and you touch it, you die.

Is this the whole code? are there anything lines of code looping this one?

This is the whole serverscript
I also have a localscript in startergui which handles the loading screen and after the loading screen is 100%, the playbutton to spawn into the game itself. That localscript works fine

I can’t seem to find any problems with your code. let me make my own and see if anything different happens

Are you certain you don’t have another script running that’s doing something similar?

The code seems to work fine. Here is my edition

function ThrowMeteors()

	for i = 1,15,1 do
		local randomPosition = Vector3.new(0,50,0) + Vector3.new(math.random(-100,100),0,math.random(-100,100))
		local MeteorClone = Instance.new("Part",workspace)
		MeteorClone.Position = randomPosition
		print("Meteor number "..i) --this stops at number 15
		wait(1)
	end

end

wait(10)

ThrowMeteors()

This spawns 15 “Parts” 50 blocks up from the origin of the map and 100 blocks in both x and z vectors.
Disable your current script and see what this one does, give me some feed back after words

Thanks, for some reason your script works how it should be but mine doesn’t. I still don’t know why mine doesn’t work, can’t find any mistakes.
Anyways thanks for your help!

You can switch out the meteorclone line with your own model if need be

1 Like

No it is my only script, now I copied the script from @roby336 and it works fine. But still thanks for trying to help!

So is the Problem solved? If so I’ll take my leave

1 Like

Yes, seems like the problem is solved. Thanks!

1 Like