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