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

How would i stop this loop at a certain part count?

I'm also wanting to make it continue under that part count, but I just don't know how. Please help!

local Region = game.workspace.Region

local Rep = game:GetService("ReplicatedStorage")
local Mine = game.ReplicatedStorage.LandMine

local x = Region.Position.x
local z = Region.Position.Z


local xS = Region.Size.X/2
local xZ = Region.Size.Z/2




while true do
		local newmine = Mine:Clone()
		newmine.Parent = workspace
		local pos1 = math.random(x-xS,x+xS)
	    local pos2 = math.random(z-xZ,z+xZ)
		newmine.Position = Vector3.new(pos1,0.2,pos2)
		wait(1)
end

3 comments

0

so like.. if parts > num then break end..?

0

Make a folder for the LandMines,

0

Make a folder for the Land Mines, this depends whether your landmines are models: local i = 0 for _,v in pairs(workspace:GetDescendants()) do if v:IsA('BasePart') then -- change BasePart to Model if the landmines r models. i = i + 1 end end print(i)

1 answer

✓ Accepted answer

Howdy!

There are many ways, such as using the break feature or simply setting the loop to run under certain circumstance. Here is an example of using the certain circumstance way.

local MineCount = 0

while MineCount > 20 do
	local newmine = Mine:Clone()
	newmine.Parent = workspace
	MineCount = Minecount + 1
	local pos1 = math.random(x-xS,x+xS)
	local pos2 = math.random(z-xZ,z+xZ)
	newmine.Position = Vector3.new(pos1,0.2,pos2)
	wait(1)
end

This would continue until you hit 20, where it will then stop running.

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

1 comment

0

I had to changed a few things, but you helped out great!

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