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

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

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

✓ Accepted answer
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.

1 comment

0

works perfectly

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