Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

your script works perfectly fine, just change :connect() to :Connect()

0

Trying to make a place roulette when ever your bored?

1 answer

✓ Accepted answer

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.

1 comment

0

thats already in his script dumbo

This discussion is preserved as it was. New answers, comments, and votes are closed.