About match random give item just 1

I want to give only 1 item and 1 item. Now I have a problem that the system gives 2 items at the same time. I’m working on a fishing system. I need to get 1 item only at random. Excuse me, I gave you a translation tool. please help me

Config
Config[“Getitems”] = {
{
Items = “bread”,
Rate = 100
},
{
Items = “water”,
Rate = 90
}
}

Server
RegisterNetEvent(Reversename … “Getfish”)
AddEventHandler(Reversename … “Getfish”, function()
local xPlayer = ESX.GetPlayerFromId(source)
for k, v in pairs(Config.Getitems) do
if math.random(99) + math.random() <= v.Rate then
if v.Items then
print(v.Items)
local xItem = xPlayer.getInventoryItem(v.Items)
if xItem.limit ~= -1 and xItem.count >= xItem.limit then
else
xPlayer.addInventoryItem(xItem.name, 1)
end
end
end
end
end)

Screenshot 2022-08-30 023417

Hey,
If I understand correctly, try adding break after xPlayer.addInventoryItem(xItem.name, 1).

xPlayer.addInventoryItem(xItem.name, 1)
break

In this order, if its problem with server-side it should work. If client-side then you’ll know if you’ve used this method.

1 Like