How would I go about looping through for i = 1,X*Y do the numbers and loop through the parts for _, v in pairs(parts:GetChildren()) do
in a way when there is a new number there is a new part, so that every part can be named after a different number from the number loop.
local X = 6
local Y = 8
local parts= workspace.parts
local part= nil
for i = 1,X*Y do
for _, v in pairs(parts:GetChildren()) do
slot = v
slot.Name = i
Please just continue your old post. https://devforum.roblox.com/t/how-to-name-parts/2331854
It lets anyone reading your post to know the back story.
You could also rename your old post when you add new information so others can see the new title and help solve your issue more effectively.
To achieve the desired functionality, you can modify your code as follows:
local X = 6
local Y = 8
local parts = workspace.parts
for i = 1, X * Y do
local newPart = Instance.new("Part")
newPart.Name = tostring(i)
newPart.Parent = parts
end
In this updated code, we iterate from 1 to X * Y using the variable i. For each iteration, a new part is created using Instance.new("Part"). The Name property of the part is set to the string representation of i using tostring(i). Finally, the new part is assigned a parent by setting newPart.Parent to parts.
This is exactly what I am looking for, but how would I do it if I wanted to name already existing parts? I originally made a new part , but I have existing ones.
If you want to rename existing parts based on the iteration number i, you can modify the code as follows:
local X = 6
local Y = 8
local parts = workspace.parts -- change this to whatever you wish
local index = 1
for _, v in pairs(parts:GetChildren()) do
v.Name = tostring(index)
index = index + 1
if index > X * Y then
break
end
end
In this updated code, we iterate over the existing parts using pairs(parts:GetChildren()). For each part, we set its Name property to the string representation of index using tostring(index). After renaming a part, we increment index by 1. The iteration continues until we have renamed X * Y parts or until we run out of existing parts by checking if index exceeds X * Y.