I remade a script and i have no errors now:
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local rollFunc = ReplicatedStorage.RollFunc
local rollR = ReplicatedStorage.Roll
local Chances = require(script.Chances)
local itemRarities = require(script.ModuleScript)
local function performMultipleRandomRolls(assets, numRolls)
local results = {}
-- Clear selectedCategorys table before performing new rolls
selectedCategorys = {}
for _ = 1, numRolls do
local totalWeight = 0
local randomValue = math.random() * 161.1601 -- Assuming your probabilities are in percentages
-- Determine the selected category based on the random value
for _, category in ipairs(Chances) do
totalWeight = totalWeight + category[2]
if randomValue <= totalWeight then
table.insert(selectedCategorys, category) -- Insert entire category into selectedCategorys
if #selectedCategorys > 5 then
table.remove(selectedCategorys, 1) -- Remove the oldest entry if more than 5 categories are stored
end
break
end
end
if selectedCategorys[#selectedCategorys][1] then
-- Retrieve the appropriate list of item IDs based on the selected category
local categoryItems = itemRarities[selectedCategorys[#selectedCategorys][1]]
if categoryItems and #categoryItems > 0 then
-- Select a random item ID from the category
local randomIndex = math.random(1, #categoryItems)
local selectedItemId = categoryItems[randomIndex]
table.insert(results, selectedItemId)
else
table.insert(results, nil) -- No items in the selected category
end
else
table.insert(results, nil) -- Invalid category selected
end
end
return results
end
local function run()
local success, response = pcall(HttpService.GetAsync, HttpService, "https://api.rolimons.com/players/v1/playerassets/1")
if not success then
warn("Failed to retrieve player assets:", response)
return
end
local data = HttpService:JSONDecode(response)
if not data or not data.playerAssets then
warn("Invalid player assets data:", response)
return
end
local newAssets = {}
for id, _ in pairs(data.playerAssets) do
table.insert(newAssets, tonumber(id))
end
table.sort(newAssets)
-- Fetch item details
local success1, response1 = pcall(HttpService.GetAsync, HttpService, "https://www.rolimons.com/itemapi/itemdetails")
if not success1 then
warn("Failed to retrieve item details:", response1)
return
end
local decodedResponse = HttpService:JSONDecode(response1)
if not decodedResponse or not decodedResponse.items then
warn("Invalid item details response:", response1)
return
end
-- Process item details
local cachedItemDetails = {}
for itemId, _ in pairs(data.playerAssets) do
if decodedResponse.items[tostring(itemId)] then
cachedItemDetails[itemId] = decodedResponse.items[tostring(itemId)]
else
warn("Item details not found for ID:", itemId)
end
end
-- Process limited items and categorize them
local rapValues = {}
for _, itemId in ipairs(newAssets) do
local itemData = cachedItemDetails[itemId]
if itemData then
local rap = itemData[3] or 0 -- Default to 0 if RAP is missing
table.insert(rapValues, rap)
else
table.insert(rapValues, 0) -- Placeholder for missing item data
end
end
-- Categorize items into rarity tiers based on RAP values
for rarity, _ in pairs(itemRarities) do
itemRarities[rarity] = {}
end
local numItems = #newAssets
for i = 1, numItems do
local itemId = newAssets[i]
local rap = rapValues[i]
if rap > 0 then
if rap <= 5000 then
table.insert(itemRarities.Common, itemId)
elseif rap <= 10000 then
table.insert(itemRarities.Uncommon, itemId)
end
end
end
-- Perform delayed roll function
task.wait(3) -- Wait for 3 seconds
rollFunc.OnServerInvoke = function(player)
local rolls = 5
local selectedAssetIds = performMultipleRandomRolls(newAssets, rolls)
-- Prepare results to send to the client
local rapValues = {}
local defValues = {}
for i = 1, 5 do
local itemId = selectedAssetIds[i]
if itemId then
local itemData = cachedItemDetails[itemId]
if itemData then
local rap = itemData[3] or 0
local defValue = itemData[5] or 0
table.insert(rapValues, rap)
table.insert(defValues, defValue)
else
table.insert(rapValues, 0) -- Placeholder if data is missing
table.insert(defValues, 0)
end
else
table.insert(rapValues, 0) -- Placeholder for nil asset ID
table.insert(defValues, 0)
end
end
-- Fire client event with results
rollR:FireClient(player, selectedAssetIds, rapValues, selectedCategorys, defValues)
print(player, selectedAssetIds, rapValues, selectedCategorys, defValues)
end
end
run()
It worked for me but i dont know will it work for you