Need help with a script that teleports the localplayer to multiple parts 1 at a time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So yeah I wanna make a script that teleports the localplayer to multiple parts in a folder, 1 at a time.
  2. What is the issue? Include screenshots / videos if possible!
    I am not very good with scripting, and I cant find any videos/posts that can help me.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Since I’m not that good with scripting I don’t know how to do this, all I got is a basic pairs loop, I also cant find any posts that have what I’m going for.
for part, v in pairs(game.workspace.Parts:GetDescendents()) do --parts is a folder containing randomly generated name parts (the names of the parts are randomly generated to prevent exploiters and such.)
    --teleport localplayer to these parts 1 at a time
end

Well, you mixed up the loop variables lol

The index would be i, or the current number in the table, and v would be the value (Or the current Part)

I believe you could just simply add a wait() depending on how fast you want to teleport to all parts, if this is a LocalScript inside StarterPlayerScripts then it should be easier:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")

for _, Part in pairs(workspace.Parts:GetDescendants()) do
    if Part:IsA("BasePart") then
        HRP.CFrame = CFrame.new(Part.Position)
        wait(1)
    end
end
1 Like