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

How do I use the same math.random() number multiple times?

local RandomInteger = math.random(1, #AvailableItemsTable)

I have a variable, RandomInteger, that is supposed to save a random number between 1 and #AvailableItemsTable. Instead the variable RandomInteger saves the function math.random(1, #AvailableItemsTable), so every time I reference RandomInteger it gives me a new random number. Is there any way I can fix this so RandomInteger is actually a random integer that I can reference multiple times while still being the same number? Thanks for reading, any help would be greatly appreciated :)

1 answer

✓ Accepted answer

What I'd so is change it to a variable.

Like so:

local randomVariable1 = math.random(1,5)
print(randomVariable1)

You can call upon the variable as much times as you want and the value will not change after determining the random value.

4 comments

0

This is literally my code... lemme check my code again, because I thought this was the case too

0

Alright it was a problem with my code elsewhere... thanks for your help, take some reputation

0

I swear I triple checked my code at least twice before I came here too

0

No worries pal.

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