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

Roblox Studio crashes when random spawning script is run?

When I run the game on Roblox studio it crashes. The script is suppose to get a random number and spawn a different part at a random position on the map.

while true do
	local zposition = math.random(64, 64)
	local xposition = math.random(64, 64)
	local yposition = 1


	local number = math.random(1,2)
	
	if number == 1 then Part1 = game.ServerStorage.Part1:Clone()
		Part1.PrimaryPart.Position = Vector3.new(zposition, xposition, yposition)
		
		if number == 2 then local number2 = math.random(1,2)
			if number2 == 1 then Part2 = game.ServerStorage.Part2:Clone()
		Part2.PrimaryPart.Position = Vector3.new(zposition, xposition, yposition)
		
		if number2 == 2 then Part3 = game.ServerStorage.Part3:Clone()
		Part3.PrimaryPart.Position = Vector3.new(zposition, xposition, yposition)
		wait(1)
		
		end
			end
		end
	end
	
end

2 comments

0

Try adding a wait to the loop

0

I've added a wait after the code but Ill try adding one before

1 answer

I managed to get it working through trial and error. Thanks for the help!

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