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

script keep spawning objects when i only want it to spawn one, what should i do?

Asked by 4 years ago

im having a lot of trouble with this statement. I basically want it so when the wave reaches "2" a boss will spawn in. i have this coded so far

while wait do
if game.ReplicatedStorage.Values.Wave.Value == 2 then
            game.ReplicatedStorage.BOSS.Zombie:Clone().Parent = game.Workspace

    else
        print("not in game")
        wait(2)
    end
end

but when the wave reaches round 2, it spawns in a bunch of the objects until the game crashes. im pretty new to scripting so how would i go about making it so it only spawns in 1 object every time the wave = 2?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Make another if statement for if the boss is already spawned in. It'll check the statement, if it's false it spawns in a Boss Zombie, then sets it to true so no more can be spawned.

local BossSpawned = false

if BossSpawned == false then
{put whatever you want here}
BossSpawned = true
0
could you elaborate on this? im still new to scripting so i apologize nick2222 20 — 4y
0
like false and true statements are in the unknown for me right now.. what would i set to false? like i see what you're saying but im not sure how i should write it out nick2222 20 — 4y
0
There you go CowboySprite 5 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

First make a variable for game.ReplicatedStorage.Values.Wave.Value Like this local wave2 = game.ReplicatedStorage.Values.Wave.Value And for the boss too. Then do ```if wave2 == 2 then```` So now you need to clone it and after :Clone() you need to set who is the parent, where you want to clone it(boss.Position = Vector3.new(?,?,?)), and you will be done.

0
He has a while statement at the top, so I don't think this will fix it, but it is good advice. CowboySprite 5 — 4y

Answer this question