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

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

Asked by 4 years ago
Edited 4 years ago

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
0
so like.. if parts > num then break end..? greatneil80 2647 — 4y
0
Make a folder for the LandMines, FTWIHATEROBLOX 0 — 4y
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) FTWIHATEROBLOX 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
I had to changed a few things, but you helped out great! larssnakes 24 — 4y
Ad

Answer this question