Making a random place teleporter but each time I rejoin the game I get placed into the same place..
01 | local Places = { "6597705" , "12468179" , "339293087" , "279238899" , "10705224" , "52681367" , "195845601" , "23243758" , "8274990" , "399059252" , "195142853" , "510444657" , "372328925" , "541548703" , "141461667" , "662417684" , "195845601" , "574407221" , "414288170" , "39972972" , "657859644" , "23243758" , "439998024" , "541548703" , "126945035" } |
02 | local TeleportService = game:GetService( "TeleportService" ) |
03 |
04 | print ( "The database has: " ..#Places.. " places available. :)" ) |
05 |
06 | math.randomseed(tick()) |
07 | game.Players.PlayerAdded:connect( function (player) |
08 | if player then |
09 | local randomId = Places [ math.random( 1 , #Places) ] |
10 |
11 | print (randomId) |
12 |
13 | TeleportService:Teleport(randomId, player) |
14 |
15 | print ( 'Bye have a great time!' ) |
16 | end |
17 | end ) |
math.random isn't truly random. Computers cannot generate random numbers so it will go in the same order every time. Use something like this to make it different each time :
1 | math.randomseed(tick()) |
2 | for _ = 1 , 10 do |
3 | --put your teleport stuff here |
4 | end |
If I didn't explain it well enough, look at this wiki page for more information on random numbers.