Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't my meteor spawner is spawning meteors?

Im making a meteor spawner so every ten seconds a meteor will spawn fifty times in the designated places. But why isnt it woking?

local server = game:GetService("ServerStorage")
local meteor = server.Meteor
while true do
	wait(10)
	for i = 50,1 do
		wait(0.5)
		local new = meteor:Clone()
		x = math.random(-128.799,140.371)
		z = math.random( -141.78,171.21)
		new.CFrame = CFrame.new(x, 155.92,z)
		new.Parent = workspace
	end
end

2 answers

✓ Accepted answer

Because your for loop isn't setup properly.

for i=50,1 do
	--the code in here will never run because `i` is already over its limit of 1
end
for i=50,1, -1 do
	--the code in here will run 50 times, because we count down from 50
end

The third number in a for loop is optional, and defaults to 1. It is the number that gets added to i each time the loop runs.

3 comments

0

still isnt running

0

^ Did you wait 10 seconds? You added a 10 second wait so the meteors won't spawn until the wait is done.

0

now it works, thanks

Your problem is that you are trying to count to 1 from 50 in the for loop which wont work. Just switch the places of the numbers and you should be good to go. It should look something like this:

local server = game:GetService("ServerStorage")
local meteor = server.Meteor

while true do

	wait(10)

	for i = 1, 50 do

		wait(0.5)

		local new = meteor:Clone()
		local x = math.random(-128.799,140.371) -- I recommend putting local in front of all variables
		local z = math.random( -141.78,171.21)

		new.CFrame = CFrame.new(x, 155.92,z)
		new.Parent = workspace

	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.