I am trying to create a code that teleports all players to the baseplate from the lobby once there are at least two players in the game. If anyone could help it would be much appreciated.
✓ ANSWER ACCEPTED
Make a script that teleports all players to a baseplate after there are 2 players in the game?
1 answer
✓ Accepted answer
This isn't a request site.
I'll try to help you though (just create a script next time!)
So first you would need to count the players in the game.
You can easily do this by counting the children of players
Get the children
Get the amount of them
Like this
while wait() do
local plrs = #game:GetService('Players'):GetChildren()
end
The # is to get the amount of them
You test the am of players using if.
To teleport the player you simply change the HRP CFrame
Like this
while wait() do
local plrs = #game:GetService('Players'):GetChildren()
if plrs >= 2 then
end
end
To get all players use for i,v in pairs
Like this
while wait() do
local plrs = #game:GetService('Players'):GetChildren()
if plrs >= 2 then
for index, plr in pairs(game.Players:GetPlayers()) do
local char = plr.Character or plr.CharacterAdded:wait() -- Get the character of the player
local HRP = char:WaitForChild('HumanoidRootPart') -- Wait For the HumanoidRootPart
HRP.CFrame = CFrame.new(x,y,z) -- CHange the XYZ with the position or use script.Parent.CFrame for example
end
end
end
Finally you want to add a debounce to not keep teleporting them
Debounce = true
while wait() do
local plrs = #game:GetService('Players'):GetChildren()
if plrs >= 2 and Debounce then
Debounce = false
for index, plr in pairs(game.Players:GetPlayers()) do
local char = plr.Character or plr.CharacterAdded:wait() -- Get the character of the player
local HRP = char:WaitForChild('HumanoidRootPart') -- Wait For the HumanoidRootPart
HRP.CFrame = CFrame.new(x,y,z) -- CHange the XYZ with the position or use script.Parent.CFrame for example
end
end
end
You can run the script again by setting the Debounce to true again
If you have a question, just ask :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Why are you helping this dude. You dont just give free answers away
Why would you use a while loop to check if there are 2 players??? This is what events are for (Players.PlayerAdded)
Same thoughts as @Kiriot22 , use PlayerAdded and if you really must do it this way, give the script more time than a pure "wait()" --> 0.03 seconds. You dont need to check 30 times every second, this will be really laggy.
Hey buddy, @Axceed_Xl, this is literally a site where people help others with scripting. Why would he waste his time giving a vague answer when he could actually just directly help the person?
Well, to answer you guys why I use a loop is because when you want to start again you won't be able too with a playeradded event, you could use it, but it could easily break and isn't that correct as a loop, you can add a 1 to the wait though to make it less laggy as it doesn't need to update every second