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

Teleport Randomly but Seperately with only 2 Players?

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?

1 comment

0

wth are you trying to do?

1 answer

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.

2 comments

0

Yeah it was definitely what I was looking for. Thanks for the knowledge

0

NP!

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