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

bad argument #2 to 'random' (interval is empty) ?

Asked by 9 years ago

output: 15:11:05.904 - Workspace.Data.Script:10: bad argument #2 to 'random' (interval is empty) 15:11:05.906 - Script 'Workspace.Data.Script', Line 10 15:11:05.907 - Stack End

local data = script.Parent
local ready = data.Ready
local chosen = data.Chosen
local p = ready:GetChildren()

while true do
    wait()
    if ready.Value >= 2 then
        wait(5)
        chosen.Value = p[(math.random(1, #p))].Name
        else
    end
end

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago
local data = script.Parent
local ready = data.Ready
local chosen = data.Chosen


while true do
    local p = ready:GetChildren()
    wait()
    if ready.Value >= 2 then
    if #p > 0 then
            wait(5)
            chosen.Value = p[(math.random(1, #p))].Name
    end
    else
    end
end

The variable p is only defined once. It will not update itself if the amount of stuff inside of it is changed. I added a check to make sure that it's greater than 0.

0
works perfectly Layfonex 0 — 9y
Ad

Answer this question