#How can i make this?

1 messages · Page 1 of 1 (latest)

proper lake
#

While making a simulator game, there's a variable inside a modulescript called currentstock, which is how many items there are in each counter, i want to make the upgrade button REFILL the items aswell, at first there are 2 of each, and it goes up by 2 every level, so whenever you upgrade the stocks by pressing the upgrade button, 2 of those items go back up into the shelves (since at the start, the excess ones go below the surface to be hidden)

#
local gs1 = workspace:WaitForChild("Map"):WaitForChild("GasStation1")
local store = gs1:WaitForChild("Store")
local interior = store:WaitForChild("Interier")
local itemsFolder = interior:WaitForChild("Items")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local stockHolder = require(ReplicatedStorage.StockHolder)

local originalPositions = {}

local function updateItemVisibility()
    for _, itemGroup in ipairs(itemsFolder:GetChildren()) do
        local visibleCount = 0
        local children = itemGroup:GetChildren()

        table.sort(children, function(a, b)
            return a.Name < b.Name
        end)

        for _, item in ipairs(children) do
            visibleCount += 1
            local shouldBeVisible = visibleCount <= stockHolder.CurrentStock

            for _, descendant in ipairs(item:GetDescendants()) do
                if not originalPositions[descendant] then
                    originalPositions[descendant] = descendant.Position
                end

                if shouldBeVisible then
                    descendant.Position = originalPositions[descendant]
                else
                    descendant.Position = originalPositions[descendant] - Vector3.new(0, 50, 0)
                end
            end
        end
    end
end
updateItemVisibility()

-- Listen for stock changes
stockHolder.StockChanged.Event:Connect(updateItemVisibility)```
#

modulsecript

#
local module = {}

module.CurrentStock = 2
module.StockChanged = Instance.new("BindableEvent")

function module.SetStock(newStock)
    module.CurrentStock = newStock
    module.StockChanged:Fire()
end

return module```
#

button script

digital geyserBOT
#

studio** You are now Level 19! **studio