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

Tables w/ math.random?

Teleports = {game.workspace.TP1,game.workspace.TP2}


while wait(5)do
	math.randomseed(tick())
		teleport:FireAllClients(math.random(1,#Teleports).Position)
end

so basically im trying to invoke all the clients to telport to either TP1 or TP2 and pass it through using the fireallclients(due to Filtering enabled) it doesnt work because math.random returns a number, or 1 or 2, but i want it to return the Brick(or TP location) from workspace as my table shows. thanks for any help, ~bubs

1 answer

✓ Accepted answer

Here is a small, clever code that would do exactly what you want:

Teleports[math.random( #Teleports )]

First it gets a random number between 1 and number of items in Teleports table and then it uses this number as index to access the table element.

Also, don't change randomseed in this kind of scenario, it will actually make it less random.

So your code would look like:

Teleports = {game.workspace.TP1,game.workspace.TP2}

while wait(5)do
	local teleport = Teleports[math.random( #Teleports )]
        teleport:FireAllClients(teleport.Position)
end

1 comment

0

alright thanks very much :)!!

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