#how can i create a limited quantity system?

1 messages · Page 1 of 1 (latest)

halcyon nexus
#

i tried this many times but failed

#

with weapons

violet crown
halcyon nexus
#

a limited quantity system

ashen plumeBOT
#

studio** You are now Level 1! **studio

ashen plumeBOT
#

studio** You are now Level 5! **studio

crimson warren
#

😭

violet crown
#

how do these ppl survive, even gpt cant work with this

thorny dirge
halcyon nexus
#

just let me know if anyone knows or not to help my game THATS ALL

halcyon nexus
#

chatgpt helps just enough

violet crown
#

@halcyon nexus spare me bro

halcyon nexus
#

sorry bro

limber jackal
#

@halcyon nexus

#

local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local StockData = DataStoreService:GetDataStore("WeaponStock_v1")
local WeaponFolder = ServerStorage:WaitForChild("LimitedWeapons")

local PurchaseRemote = Instance.new("RemoteFunction")
PurchaseRemote.Name = "PurchaseWeapon"
PurchaseRemote.Parent = ReplicatedStorage

PurchaseRemote.OnServerInvoke = function(player, weaponName)
local success, currentStock = pcall(function()
return StockData:GetAsync(weaponName)
end)

if success and currentStock and currentStock > 0 then
    local weaponModel = WeaponFolder:FindFirstChild(weaponName)
    
    if weaponModel then
        local updateSuccess, newStock = pcall(function()
            return StockData:UpdateAsync(weaponName, function(oldValue)
                if oldValue and oldValue > 0 then
                    return oldValue - 1
                end
                return nil
            end)
        end)

        if updateSuccess and newStock then
            local tool = weaponModel:Clone()
            tool.Parent = player.Backpack
            return true, newStock
        end
    end
end

return false, 0

end

#

server script

#

i dont know how u want it