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

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

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

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

3 comments

0

could you elaborate on this? im still new to scripting so i apologize

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

0

There you go

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.

1 comment

0

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

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