Need help in loops

how I can get one part in folder

local FolderPart = game.Workspace.Folder:WaitForChild("Parts")

for _,Part in FolderPart:GetChildren() do
	---how i can get one part of the folderpart
end

You could do:

FolderPart[“name_of_part”]

Not sure if this is what you’re asking for

2 Likes

or, if you want inclusivity / exclusivity to an action, you can also do

if part.Name == "name_of_part" then
    --bla bla bla
end
2 Likes

I’m trying to take one part form Folder because I don’t want write names of parts one by one

image

You can just do FolderPart:GetChildren()[1].

2 Likes

If you can’t identify by name, what are you trying to identify by? Colour? Size? CFrame? Position? What are you even trying to do?

1 Like

give me an erro code

ServerScriptService.GameScript.Teams.TeamHandle:17: attempt to iterate over a Instance value 

i need wen the player joine game get one part and rename to has name

You don’t have to iterate through it, just replace the loop with what I sent to you, that should only return one random part from the folder you specified. Not sure what you’re exactly trying to achieve tho.

1 Like

done i make new way

local PlayerRoom = game.Workspace:WaitForChild("Folder"):WaitForChild("PlayerRoom"):GetChildren()


while wait( 5) do
	local RanodmNumbers = math.random(1, # PlayerRoom)
	local Room = PlayerRoom[RanodmNumbers]
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.