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

teleporting two random people to one place?

I am having trouble getting started with a script. The script will take 2 ppl from the server and tp to a differtent spot in ther server. I would really appreciate if someone helped me get started or make me the script!!! can u guys please help me get started?

1 answer

✓ Accepted answer

There are two parts to this script. The first one is getting two random people, and the second is teleporting them to their destination.

I recommend creating a table of all players:

local allPlayers = {}
for a,v in pairs(game.Players:GetChildren()) do
	table.insert(allPlayers,v)
end

Next just randomly pick two numbers, that are less than or equal to the amount of players:

local plrAmount = game.Players.NumPlayers
local val1 = math.random(plrAmount)
local val2
repeat
	val2 = math.random(plrAmount)
	wait()
until val2 ~= val1 -- Keep choosing a new random number for val2 until we have two different numbers

Then, teleport the players

allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allPlayers[val2].Character.Torso.CFrame = CFrame.new(0,0,0)

Make sure the script makes sure there are 2 players or more! Also, you may want to look up how to make your random numbers different each time the place is run. More information on that, here.

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