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
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.
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