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

Why the enemies are over spawning?

THIS IS ONLY THE PIECE OF THE SCRIPT, THE ENTIRE SCRIPT HAS 150 LINES!!!!!

spawnAnotherAt=50
nextSpawn=0

if nextSpawn<=0 then
	newai=game.Lighting.Enemy:clone()
	spot=math.random(1,2)
	if spot==1 then
		newai.Position=UDim2.new(0,0,0.65,0)
	else
		newai.Position=UDim2.new(0.96,0,0.65,0)
	end
	newai.Parent=script.Parent
	if spawnAnotherAt >= 2 then
		spawnAnotherAt = spawnAnotherAt -0.9
	elseif spawnAnotherAt <= 2 or spawnAnotherAt == 2 then
		spawnAnotherAt = 2
	end	
	nextSpawn=spawnAnotherAt
	print(spawnAnotherAt)
end

So what this piece of script does is to set the enemies spawning of a gui minigame. Between lines 13-17 is to set that spawn another at minimal number gets to two, witch means the it will spawn a the next enemy in 2 frames. But theres a problem, the spawnanotherat doesnt stop in 2, it just keeps going, making the game lag and create a lot of enemys of a time.

1 comment

0

If the script is copying itself then each copy is going to run and it's going to replicate forever and crash.

1 answer

Change it to spawnAnotherAt > 2, it's because it'll never be less than 2

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