Random number wait loop

I want a script to output a random number between 100 and 999
this is what I have so far:

local function newNumber()
	local number = math.random(100,999)
end
while true do
	task.wait(20)
	newNumber()
end

but for some reason this doesn’t work. Someone please help me

What do you mean that it doesn’t work? That will definitely work.

local function newNumber()
	return math.random(100, 999)
end

print(newNumber)

Have I stated that it was every 20 seconds?

You forgotten the print statement and return :slight_smile:

1 Like
local newNumber = function(range)
local minimum = range[1];
local maximum = range[2];
return math.random(minimum, maximum)
end

while true do
task.wait(20)
print(newNumber({100, 999}));
end
local function newNumber()
	local number = math.random(100,999)
    print(number) -- puts number to your output log
end
while true do
	task.wait(20)
	newNumber()
end

It just does this now.

local function newNumber()
	local number = math.random(100,999)
end
while true do
	task.wait(20)
	print(newNumber())
end

Try this code I sent earlier:

local newNumber = function(range)
local minimum = range[1];
local maximum = range[2];
return math.random(minimum, maximum)
end

while true do
task.wait(20)
print(newNumber({100, 999}));
end

Right add a return instead of the variable.

local function newNumber()
	return math.random(100,999)
end
while true do
	task.wait(20)
	print(newNumber())
end
2 Likes

Right that’s because the function newNumber doesn’t return anything so print won’t print anything since you are feeding it nothing. you can change the variable declaration to a return.

local function newNumber()
	return math.random(100,999)
end
while true do
	task.wait(20)
	print(newNumber())
end
2 Likes

You got the answer, good afternoon body!