So I’m going to be copy + pasting the same part quite a bit, and I need them to be named part1, part2, part3, etc (going up to the number of parts there are). Would there be a way to do this to all parts with a certain name automatically in studio?
I hope I understood you correctly
for i = 1,20 do
local newPart = instance.new("Part")
newPart.Name = "Part"..tostring(i)
newPart.Parent = game.Workspace
end
or -
for i = 1,#game.Workspace.MyParts:GetChildren() do
local newPart = instance.new("Part")
newPart.Name = "Part"..tostring(i)
newPart.Parent = game.Workspace
end
--replace game.Workspace.MyParts:GetChildren() with your table containing whatever items/objects
I’m not very good with scripting so please correct me if I’m wrong, but I think that would be creating new parts, right? What I mean is if I copy + pasted the same part manually about 100 times with the name “testpart”, I would need a way to automatically rename them in studio (not just while playing the game), with the names being part1, part2, … all the way to part100, if that makes sense?
Make sure to use tostring(i)
and not just i
.
i
is an Index number, stored as an integer, and trying to add this to a string will error out.
A nice way of doing it within studio is by using the Selection service.
What I like to do often is this:
local Selection = game:GetService("Selection")
for i,v in ipairs(Selection:Get()) --// Get currently selected objects
v.Name = "Part" .. i
end
If you want to run it, just put it in the commandbar at the bottom of your screen. If you don’t see it, then go to the View tab and enable it.
This will not error. Luau will automatically convert it to a string.
Okay so I put it in the command bar but it’s erroring:
Sorry I’m not used to doing stuff like this at all so I really have no idea what I’m doing
Woopsie, I forgot to put ‘do’
local Selection = game:GetService("Selection")
for i,v in ipairs(Selection:Get()) do --// Get currently selected objects
v.Name = "Part" .. i
end
I’d create a model or folder, put the relevant part in that organizer, then create a ChildAdded function through the studio command line to assign names.
Ohh okay it worked now, thank you soo much!