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

There is a folder with 8 parts in it and I want all 8 players to be teleported to each of them?

I have 8 parts in a folder and I want them all teleported to each part how do I do this this is my code so far:

local numplayers = #game.Players:GetChildren()
while true do
if numplayers <= 8 then
		for i,v in pairs(game.Players:GetPlayers()) do
			part = game.Workspace.Folder.Part1
			v.Character.HumanoidRootPart.Position = part.Position + Vector3.new(0,5,0)
			part = part + 1
		end
	end
end

2 comments

0

Sorry about that, forgot to add a wait so the script may have been timing out causing it not to work. I fixed it to where it should work now lol.

0

thank you so much

2 answers

You're actually super close. There's a few ways you can do this involving tables but it looks like you have your parts named as Part1, Part2, etc. so I'm just going to change your variable a bit:

local numplayers = #game.Players:GetChildren()
while true do
if numplayers <= 8 then
        for i,v in pairs(game.Players:GetPlayers()) do
            part = game.Workspace.Folder["Part".. tostring(i)]
            local hrp = v.Character.HumanoidRootPart
            hrp.CFrame = CFrame.new(part.Position + Vector3.new(0,5,0))
        end
    end
    wait(5)
end

Because i is the number of times the for loop has run at that point, it will start at 1 and go up to however many players you have. If you're unfamiliar with strings, what I'm doing is taking the string, "Part", and then adding .. after which allows you to attatch strings together. Example:

print("Hello World")

-- is the same as

print("Hello".. " World")

What I'm doing after the .. is adding a tostring() because i is a number value and we need it to be a string for our purposes. This should work however I don't have access to studio at the moment so if it doesn't than comment any errors.

1 comment

0

I do not think it gave any errors but I tried 8 person test and it did not work

Hello,

We need to loop it like so, we will count the player with a for loop.

while true do
	local Players = game.Players:GetChildren() -- Gets Children
	if #Players <= 8 then
		for Number, Player in pairs(game.Players:GetChildren()) do -- Loops through children
			local Folder = game.Workspace.Folder:GetChildren()
			Player.Character:WaitForChild("HumanoidRootPart").Position = Folder[Number].Position
		end
	end
	wait(.5)
end

What is good about Folder:GetChildren()[x] is that you don't have to name the children of the folder to 1, 2, 3 etc

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