Ensuring a certain amount of certain blocks spawns in grid

Hi, DevForum. For the first time, ChatGPT did not help. In my game, a grid of parts will spawn, with some parts being special (by chance). How can I make sure that there is a certain number of special parts in the grid?

local function createBlock(position, size, material, color)
	local block = Instance.new("Part")
	block.Size = size
	block.Anchored = true

	block.Material = material
	block.Color = color

	local chance = math.random(1, specialBlockChance or 150)
	if chance == 1 then
		registerSpecialBlock(block)
	end

	-- Pick a random shape
	block.Shape = shapes[math.random(1, #shapes)]

	block.Position = position

	-- Tag as DigBlock
	CollectionService:AddTag(block, "DigBlock")
	block.Name = "Block"
	block.Parent = folder
end

sorry, my mushy programmer brain is not behaving well at 11:30 pm. i will loop through the grid when it’s created (a for loop with a count of the specified amount) and make a random block a special one.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.