I am trying to set a part for each player to be teleported to when the game starts. I have a folder of 15 parts where I want the players to spawn. The max player amount is 15. However I have this script here and I attempted to get the value to be true if the player is teleported to it, but it just sets all the values under all the parts in the folder to true. I know that it is looping but I am not sure how to reference the part outside of the loop.
for i, part in pairs (teleportSpawns:GetChildren()) do
if part:FindFirstChild("Occupied").Value == false then
for _, v in pairs(P_S:GetChildren()) do
local character = v.Character
local HRP = character:WaitForChild("HumanoidRootPart")
v.Character:MoveTo(part.Position)
end
end
part.Occupied.Value = true
end
I am not sure if this is the best way to do this task either. If anyone knows how I can reference the part outside the loop or have any ideas on how I can complete the task please let me know.
Thanks.
P_S is
game:GetService("Players")