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

How do I teleport all players to a block(spawn) and one random player to another block?

I want to make a game where one random player spawns at one point while the rest of the players spawn at another block. I truly appreciate all your help but I am really trying to learn how to code in Roblox. I barely started two weeks ago and thanks to you guys, I can now clone blocks, create debounces, and create block GUI's on my own. My first game is almost done but I can't do it without you guys. Here is my current script:

local TextBox = script.Parent
local Spawn = game.Workspace.Spawn

if TextBox then
TextBox.Text = 'intermission'
wait(4)
TextBox.Text = '10'
wait(1)
TextBox.Text = '9'
wait(1)
TextBox.Text = '8'
wait(1)
TextBox.Text = '7'
wait(1)
TextBox.Text = '6'
wait(1)
TextBox.Text = '5'
wait(1)
TextBox.Text = '4'
wait(1)
TextBox.Text = '3'
wait(1)
TextBox.Text = '2'
wait(1)
TextBox.Text = '1'
wait(1)
TextBox.Text = "loading"
wait(3)

game.Players.PlayerAdded.Position = Spawn.Position	
	end

I know that there are math scripts to do the -1 second instead of typing all the text scripts, but that will be for another time. When the loading text starts and the wait is over, I want one player to be randomly selected to spawn at one point, the rest to another. I would love for you to be so kind and teach me how to script this. Thank you so much!

Sincerely,

Or2no

1 answer

✓ Accepted answer
local TextBox = script.Parent
local Spawn = game.Workspace.Spawn
local OtherPart = workspace.INSERTPARTHERE

if TextBox then
TextBox.Text = 'intermission'
wait(4)
TextBox.Text = '10'
wait(1)
TextBox.Text = '9'
wait(1)
TextBox.Text = '8'
wait(1)
TextBox.Text = '7'
wait(1)
TextBox.Text = '6'
wait(1)
TextBox.Text = '5'
wait(1)
TextBox.Text = '4'
wait(1)
TextBox.Text = '3'
wait(1)
TextBox.Text = '2'
wait(1)
TextBox.Text = '1'
wait(1)
TextBox.Text = "loading"
wait(3)

for i,v in pairs(game:GetService("Players"):GetPlayers()) do
	v.Character.HumanoidRootPart.CFrame = Spawn.CFrame -- gets all players and teleports them to spawn.
end
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = OtherPart.CFrame
break -- this break will stop the loop from being run more than once; only teleporting a single player to the "OtherPart".
end

You were trying to teleport the player, not the player's character. Please also don't use "PlayerAdded" because it will not get all players in the current game. I added a variable, "OtherPart" that you can edit around yourself. If this doesn't work or you have questions, feel free to add a comment!

6 comments

0

if you'd also like me to set up the "math" equation, please comment aswell.

0

Already looking at the script, I have questions. Throughout Youtube videos and other script responses, I see people state letters such as in this case: i and v. What do these letters represent? It always confused me to see for i, v in pairs. I would also like to know what pairs does in a script. Thank you :)

0

The letters can be changed; and they don't have any effect on the command. If you'd like to ask more questions, since I don't like to paragraph on SH, my Discord is aman#8707. For Instance, "for i,v in pairs(game:GetService("Players"):GetChildren()) do print(i,v)". When this prints, nothing will be the same. If you have one player in the game, it will print: "1 PlayerName". If you have two players

0

(line - downs are marked by "--") : "1 PlayerName -- 2 PlayerName". I know this is not a good way to make you understand, but SH formatting is difficult.

0

print v.Name*

0

For the second question of your comment, a "for" loop just runs through an object's children, and gets their data. These are stored in the default, I and V. I being the number from the parent, and V being the actual object inside of the parent. It's a very simple concept, but it is massively relied on by many programmers. Hope I could help :)

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