Edit: i added the full script
i've been trying to get this script to select a random child with a specific name like "9mm"
rEvent4.OnServerEvent:Connect(function(plr)
if ammo.Value < 15 then
local backpack = plr.Backpack:GetChildren()
local all9mm = {}
for i, v in ipairs(backpack) do
if v.Name == "9mm" then
table.insert(all9mm, v)
end
end
local chosenitem = all9mm[math.random(1, #all9mm)]
print(chosenitem.Name)
end
end)

6 comments
it works thank you!
ok wait i have a problem
the script prints out 2 or more random items when its just supposed to be 1 random item
make sure the last two lines are outside of the for loop so that they only happen one time
i did but it still happens
ok it worked, just had to put a if not debounce function between them