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

Spawning script spawns multiple on top of each other? [Unanswered]

Asked by 9 years ago

I have a script, it works fine the first wave, but when you get to the second wave, it spawns in groups of five on top of each other and lags the game like crazy! Here is the script

repeat
wait(1)
if script.WaveHas.Value == 0 then
if script.Parent.WaveCount.Value == 2 then
script.WaveHas.Value = 1
local AmountOfWaves = 15 -- How many waves do you want? Put them here
local TimePerWave = 5 -- How long you want to wait per wave

local function SpawnWave()
    local Bot = game.ReplicatedStorage.Alien:Clone()
    Bot.Parent = workspace
    Bot:MoveTo(Vector3.new(math.random(-254,254), 5, math.random(44,255)))

end

for CurrentWave = 1, AmountOfWaves do
    SpawnWave()
    wait(TimePerWave)
end
script.Parent.TimeLeft.Value = 120
wait(120)
script.Parent.WaveCount.Value = 3
print("set to wave 3")
end
end
until script.Parent.WaveCount.Value > 2

Please help!!! Thank you!!! PS. each wave is in a different script, but are all the same (other than variables such as WaveCount)

1 answer

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
9 years ago

The Problem:

I can tell, 15 groups are being spawned due to your 'for' sequence

Script:

Not tested I hope this works, reply if it does/doesn't

repeat
wait(1)
AmountOfAliens = 2 -- Amount of aliens for a wave, change it in the scripts if you want
if script.WaveHas.Value == 0 then
if script.Parent.WaveCount.Value == 2 then
script.WaveHas.Value = 1
local AmountOfWaves = 15 -- How many waves do you want? Put them here
local TimePerWave = 5 -- How long you want to wait per wave

local function SpawnWave()
    local Bot = game.ReplicatedStorage.Alien:Clone()
    Bot.Parent = workspace
    Bot:MoveTo(Vector3.new(math.random(-254,254), 5, math.random(44,255)))

end

for CurrentWave = 1, AmountOfAliens do
    SpawnWave()
    wait(TimePerWave)
end
script.Parent.TimeLeft.Value = 120
wait(120)
script.Parent.WaveCount.Value = 3
print("set to wave 3")
end
end
until script.Parent.WaveCount.Value > 2
0
Nope, didn't work, thanks though yogipanda123 120 — 9y
Ad

Answer this question