Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why the enemies are over spawning?

Asked by 10 years ago

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.

0
If the script is copying itself then each copy is going to run and it's going to replicate forever and crash. 1waffle1 2908 — 10y

1 answer

Log in to vote
0
Answered by
aews5 15
10 years ago

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

Ad

Answer this question