• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: how could i make this keypad have a random code every time you join? (roblox studio/lua)

Resolved: how could i make this keypad have a random code every time you join? (roblox studio/lua)

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

this is what i have right now and i have no clue how to even make random stuff (other than math.random, which doesn’t work) can someone help with this please? i’ve been trying different things for hours and can figure out how to do any randomize codes

Answer:

(to preface, i dont know anything about roblox specifically, just lua in general) math.random is the thing to use, but it requires some specific for your case.
presuming that you need a 4-digit integer code, math.random(1,9999) should give that (http://lua-users.org/wiki/MathLibraryTutorial). Then, to compare it with the input (which i see is a string), you can either turn the input to a number (tonumber("1234")), or the actual code to a string (tostring(math.random(1,9999)).
Since lua does not care for floats/integers/etc, just numbers, I would go with the tonumber route, since you dodge string formatting that way.
To seed your randomiser, you can use math.randomseed(), for example with the system time (since the seed will be different every time, the code will be different every time). note that that sets the seed for any random call after that, not just that one call.
I hope this helped.

If you have better answer, please add a comment about this, thank you!

lua roblox
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Use Svelte Component as Slot

26/03/2023

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Resolved: How to separate multiple answers in one column, for multiple columns, by creating extra columns

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.