Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the script having a error?

Asked by
mine248 40
8 years ago

I created a script, and testing it, and it gave a weird error I can't understand.

14:38:27.943 - ServerScriptService.Script:103: bad argument #2 to 'random' (interval is empty)

14:38:27.944 - Script 'ServerScriptService.Script', Line 103

14:38:27.945 - Stack End

Any solution?

Faulty code:

while true do
    contestants = {}
    blue = {}
    yellow = {}
    green = {}
    for _, player in pairs(game.Players:GetPlayers()) do
        if player and player.Character then
            local humanoid = player.Character:WaitForChild("Humanoid")
            if humanoid and humanoid.Health > 0 and player.TeamColor.Name == "Lime green" then
                table.insert(contestants, player)
                table.insert(green, player)
            elseif humanoid and humanoid.Health > 0 and player.TeamColor.Name == "New Yeller" then
                table.insert(contestants, player)
                table.insert(yellow, player)
            elseif humanoid and humanoid.Health > 0 and player.TeamColor.Name == "Really blue" then
                table.insert(contestants, player)
                table.insert(blue, player)
            end
        end
    end
    local bluerep = blue[math.random(1, #blue)]
    local yellowrep = yellow[math.random(1, #yellow)]
    local greenrep = green[math.random(1, #green)]
    bluerep:MoveTo(game.Workspace.R62_Trk1.Model.VehicleSeat.Position)
    yellowrep:MoveTo(game.Workspace.R62_Trk3.Model.VehicleSeat.Position)
    greenrep:MoveTo(game.Workspace.R62_Trk4.Model.VehicleSeat.Position)
end
0
If no players are on Blue, Yellow, or Green then that would mean lines 21 - 23 could consist of `local colorrep = color[math.random(1,0)]` The second argument in the math.random function CAN NOT be smaller than the first argument. Goulstem 8144 — 8y

Answer this question