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: Choose a Random Variable.

Previous Thread :: Next Thread 
dude10000009 is not online. dude10000009
Joined: 23 Nov 2010
Total Posts: 809
25 Jul 2016 03:37 PM
So i using a code which will assign teams but i want it to be random?
Any help?

local Blue = Instance.new("Team")
Blue.TeamColor = BrickColor.new("Bright blue")
Blue.Parent = game:GetService('Teams')
Blue.Name = "Blue"
local Red = Instance.new("Team")
Red.TeamColor = BrickColor.new("Bright Red")
Red.Parent = game:GetService("Teams")
Red.Name = "Red"

-- Assign Randomly
T = {"Blue","Red"}
plr.Team = (table[math.random(1, #T)])
Report Abuse
arshiaslaya is not online. arshiaslaya
Joined: 04 Nov 2012
Total Posts: 2670
25 Jul 2016 03:38 PM
Use math.random and a random seed
Report Abuse
dude10000009 is not online. dude10000009
Joined: 23 Nov 2010
Total Posts: 809
25 Jul 2016 03:43 PM
Can you clarify Random, seed? no documentation on it
Report Abuse
MisunderstoodOwl is not online. MisunderstoodOwl
Joined: 04 Oct 2014
Total Posts: 181
25 Jul 2016 03:45 PM
Random doesn't exist as far as your computer is concerned. It uses a mathematical process which is known as pseudo-random number generation. To do this, it requires a seed to produce results that appear random. Common practice is to set the seed to tick()%1e6, to do this you'd use the line math.randomseed(tick()%1e6). I'm pretty sure tick() returns the seconds since the start of UNIX time (or something along those lines); as a result it will always be a different number and your pseudo-random outcomes should always be different
Report Abuse
dude10000009 is not online. dude10000009
Joined: 23 Nov 2010
Total Posts: 809
25 Jul 2016 03:48 PM
Thanks but how would i go about using it if it was a variable, im guessing the variable would be a specific number? as it is a string
Report Abuse
dude10000009 is not online. dude10000009
Joined: 23 Nov 2010
Total Posts: 809
25 Jul 2016 03:50 PM
Sorry as it is a variable
Report Abuse
MisunderstoodOwl is not online. MisunderstoodOwl
Joined: 04 Oct 2014
Total Posts: 181
25 Jul 2016 03:53 PM
randomseed is not the random variable - it sets the random generator up to produce random results. You need to change the line:

plr.Team = (table[math.random(1, #T)])

to

plr.Team = T[math.random(1,#T)]
Report Abuse
dude10000009 is not online. dude10000009
Joined: 23 Nov 2010
Total Posts: 809
25 Jul 2016 03:57 PM
Thank you very much :)
You are the only one that has explained the meaning of a function which is really helpful thank you.
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