Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Math.random error, interval is empty?

"Workspace.Wood Crate.Script:14: bad argument #1 (interval is empty)"

local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")

local weapons = serverStorage.Weapons:GetChildren()

local loot = script.Parent
local part = loot.PrimaryPart

part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
    if (humanoid and humanoid.Health > 0) then
        local player = players:GetPlayerFromCharacter(hit.Parent)
        local backpack = player:WaitForChild("Backpack")
        local clonedWeapon = weapons[math.random(#weapons)]:Clone()
        clonedWeapon.Parent = backpack
        loot:Destroy()
    end
end)

1 answer

It's now solved. If this happens to you, just make sure the items are in the referenced place. Like I forgot that the weapons are not in the Weapons folder. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.