generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Random Rumbers Help

Previous Thread :: Next Thread 
CrystalFlameTM is not online. CrystalFlameTM
Joined: 17 Jul 2014
Total Posts: 24
14 Sep 2016 06:21 AM
Is there a way to choose random out of a set of specific numbers? Please help me!
Report Abuse
john269962 is not online. john269962
Joined: 25 Jun 2008
Total Posts: 166
14 Sep 2016 06:28 AM
local numberList = {1,2,3,4,5,6,7,8,9,11,45,51}

return numberlist[math.random(#numberList)]
Report Abuse
CrystalFlameTM is not online. CrystalFlameTM
Joined: 17 Jul 2014
Total Posts: 24
14 Sep 2016 06:32 AM
Thank you!
Report Abuse
CrystalFlameTM is not online. CrystalFlameTM
Joined: 17 Jul 2014
Total Posts: 24
14 Sep 2016 06:34 AM
Wait. How would you test if it chose one of those numbers?
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 06:41 AM
it depends if you're running the script right off the bat in the server or if the random number is being chosen at different times, like for example the damage of a sword might be random

if the script is running as soon as the game starts, you need to have

math.randomseed(tick()) in the script before the number is chosen
this ^ sets math.random's procedural sequence to make it completely random (you also only need it in one script in your game, once it is set in one script it works for them all)

see this:
http://wiki.roblox.com/index.php?title=Random_numbers

to see if it is selecting a random number, the easiest way is to just use a print. so your finished script will want to look something like this:

math.randomseed(tick())
local numberList = {1,2,3,4,5,6,7,8,9,11,45,51}
local chosenNum = numberlist[math.random(#numberList)]

print(chosenNum)


Report Abuse
CrystalFlameTM is not online. CrystalFlameTM
Joined: 17 Jul 2014
Total Posts: 24
14 Sep 2016 06:48 AM
Its being used for a random way to get a random amount of xp. Then a other script detects if the number is something then makes a certain mesh appear. But I don't wan to print it to the dev console. I want it to be detected in a if statement.
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 07:03 AM
test (forum broke and wouldn't let me respond)


Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 07:07 AM
Okay, the forum is being stupid and for whatever reason won't let me post what I was trying to post.

SO I'll try posting it in parts.

Part 1/3

if its from an enemy, you don't need to worry about the random.randomseed(tick()) thing.
it may be easier to do it all in one script (in the enemies model) using functions:


Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 07:09 AM
it won't let me post the rest of it...... "Bad Request" I tried messaging it to you and roblox threw up another error... ######
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 07:11 AM
##############################################
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 07:11 AM
Oh my god.. ROBLOX needs to die.

Yeah, sorry man. I can't help you out because roblox literally will not let me send the solution to you..


Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
14 Sep 2016 09:29 AM
local randomInteger = math.random(Min,Max)
local randomNumber = Min + math.random()*(Max-Min)
local randomIndex = A_Table[math.random(#A_Table)]
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
14 Sep 2016 09:32 AM
paste bin: uQnAALqC


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
14 Sep 2016 09:36 AM
local nums = {1,2,3,4,5}

local ranNum = nums[math.random(1,#nums)]

if ranNum == 5 then
--do something
end


Report Abuse
CrystalFlameTM is not online. CrystalFlameTM
Joined: 17 Jul 2014
Total Posts: 24
15 Sep 2016 06:21 AM
Thanks!
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
15 Sep 2016 07:25 AM
--this one is better for ranges to prevent spamming numbers

local ranges = {
{1,5,0.25}; --min,max,step
{10,70,2};
}

function random(range)
local rngind = math.random(#range)
local rng = range[rngind]
return math.random(rng[1]/rng[3],rng[2]/rng[3])*rng[3],rngind
end

while true do
print(random(ranges)) --returns random number in ranges and the index of it
wait(0.4)
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image