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

teleporting two random people to one place?

Asked by 8 years ago

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

Log in to vote
2
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

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.

Ad

Answer this question