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

how do i limit how many bricks can be spawned?

Asked by 4 years ago

i'm making some stupid brick factory game thing and i need to add a limit to how many bricks can be spawned at once (not in general) so i can avoid people lagging the server

you spawn bricks with the press of a button, anyway heres the script

local part = script.Parent
local h = 0.5
local ohno = 60
local db = false

part.ClickDetector.MouseClick:connect(function(player)

    local bruh = Instance.new("Part", workspace)
    bruh.Anchored = false
    bruh.Position = game.Workspace.jeff.Position
    bruh.Material = Enum.Material.Brick
    bruh.BrickColor = BrickColor.Random()
    bruh.Transparency = 0
    bruh.Size = Vector3.new(2, 2, 2)
    part.BrickColor = BrickColor.new("Really red")
    wait(h)
    db = true
    part.BrickColor = BrickColor.new("Lime green")
    wait(h)
    db = false
    wait(ohno)
    bruh:Destroy()
end)

i'm thinking of doing an if statement but i was like nah

3 answers

Log in to vote
0
Answered by 4 years ago

What I would do, I know it’s probably not the best way but, I’d just put a timer so like every minute or something it clears the bricks. You can also add a recharge on the tool so that you have to wait like 2 seconds or something before spawning another brick. Tell me iif you need help with code! Hope you are well.

0
i've already added a brick removal thing, line 21 and 22 greendayshade 5 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

An easy solution (there are lots of solutions to this) would be to put them all in the same folder then use getChildren to return a list of arts and count them.


local folder = Instance.new('Folder') folder.Name = 'parts' folder.Parent = workspace local partLimit = 10 part.ClickDetector.MouseClick:connect(function(player) if #folder:GetChildren() > partLimit then return end -- do not run if there are more parts than the limit -- normal code ..... end)

I hope this helps. Please comment if you have any other questions about this code.

0
As I said, my way isn’t good lol. That sounds like a good method though! lincol92008 46 — 4y
0
hmmm.. doesn't seem to work but i'm going to try to fix it, perhaps it's because the button is in a model or something like that greendayshade 5 — 4y
0
Check that you are parenting the parts to the folder. User#5423 17 — 4y
Log in to vote
0
Answered by 4 years ago

Well if you ask me, I will add an "IntValue" into the part and do it this way:

local part = script.Parent
local h = 0.5
local ohno = 60
local db = false
local IntValue = part:WaitForChild("IntValue")

part.ClickDetector.MouseClick:connect(function(player)
    if IntValue.Value <= 2 then -- Once the IntValue reached a certain value, the following codes below will not run (feel free to change "2" to the brick limit you want)
        IntValue.Value = IntValue.Value + 1 -- every time when a player clicks, the int value will go up by 1
        local bruh = Instance.new("Part", workspace)
        bruh.Anchored = false
        bruh.Position = game.Workspace.jeff.Position
        bruh.Material = Enum.Material.Brick
        bruh.BrickColor = BrickColor.Random()
        bruh.Transparency = 0
        bruh.Size = Vector3.new(2, 2, 2)
        part.BrickColor = BrickColor.new("Really red")
        wait(h)
        db = true
        part.BrickColor = BrickColor.new("Lime green")
        wait(h)
        db = false
        wait(ohno)
        bruh:Destroy()
    end
end)

Answer this question