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

Teleport Randomly but Seperately with only 2 Players?

Asked by 6 years ago

Only 2 Players are allowed, so it is probably much easier to script.

I dont know how to make sure they both get teleported seperately though..

i know how to teleport 1 random pretty sure:

Local Script

for i = 1, #game.Players:GetChildren() do
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = TPBrick1.CFrame 
end

But I dont know how to reference the other player?

0
wth are you trying to do? User#20388 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Err... First of all, you should probably do this instead:

for _, player in pairs(game:GetService("Players"):GetPlayers()) do
    -- game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = TPBrick1.CFrame
end

And perhaps this shall help you.

-- Best in a regular script, depends on what you are doing. This should run immediately.
local Players = game:GetService("Players") -- get the Players service
local PlayerTable = {} -- we'll need this
local NextEntryNumber = #PlayerTable + 1 -- helps
while true do -- let's make a loop to keep track of the players
    PlayerTable = {} -- empty out the table
    for _, player in pairs(Players:GetPlayers()) do -- check all the players
        PlayerTable[NextEntryNumber] = player -- let's poof in dat player
    end
    wait(5) -- wait five seconds per update
end
-- le following does the teleport
local NumPlayers = #PlayerTable -- number of players
local PickerOne = math.random(NumPlayers) -- let's find a random number with a maximum of the amount of players
local PickerTwo = math.random(NumPlayers) -- let's make another one
for i = 1, 3 do -- let's run this code three times just to be safe
    if PickerOne == PickerTwo then -- if they're the same
        PickerTwo = math.random(NumPlayers) -- reset PickerTwo
    end
end
local andthewinneris = PlayerTable[PickerOne] -- grab the player PickerOne chose
local andtherunnerup = PlayerTable[PickerTwo] -- grab the player PickerTwo chose
andthewinneris.Character.HumanoidRootPart.CFrame = TPBrick1.CFrame -- tp the first player
andtherunnerup.Character.HumanoidRootPart.CFrame = TPBrick2.CFrame -- or TPBrick1, if they both go to the same spot.

The script above will pick two random players from the game and teleport them to TPBrick1 and TPBrick2, respectively.

If this is not what you're looking for, please comment on my answer and tell me the condition you want the players to be teleported with.

0
Yeah it was definitely what I was looking for. Thanks for the knowledge MusicalDisplay 173 — 6y
0
NP! sweetkid01 176 — 6y
Ad

Answer this question