Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is math.random not choosing random places out of table?

Asked by 7 years ago

Making a random place teleporter but each time I rejoin the game I get placed into the same place..

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"}
local TeleportService = game:GetService("TeleportService")

print("The database has: "..#Places.." places available. :)")

math.randomseed(tick())
game.Players.PlayerAdded:connect(function(player)
    if player then
        local randomId = Places[math.random(1, #Places)]

        print(randomId)

        TeleportService:Teleport(randomId, player)

        print('Bye have a great time!')
    end
end)

0
your script works perfectly fine, just change :connect() to :Connect() PyccknnXakep 1225 — 7y
0
Trying to make a place roulette when ever your bored? NexoKami 12 — 7y

1 answer

Log in to vote
1
Answered by
Viking359 161
7 years ago

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 :

math.randomseed(tick())
for _ = 1, 10 do
--put your teleport stuff here
end

If I didn't explain it well enough, look at this wiki page for more information on random numbers.

0
thats already in his script dumbo F4ULT1NTH3D4T4 226 — 7y
Ad

Answer this question