|
| 21 Oct 2017 06:00 PM |
| Basically if, for example Bob, exists in the Workspace then the next one will be called Bob1 then Bob2 etc.. Could anyone plz tell me how to make the script |
|
|
| Report Abuse |
|
|
LuaDesign
|
  |
| Joined: 24 May 2010 |
| Total Posts: 1336 |
|
|
| 21 Oct 2017 06:07 PM |
for i,v in pairs(workspace:GetChildren()) do if v.Name:sub(1,#"bob"):lower() == "bob" then v.Name = v.Name..i end end
|
|
|
| Report Abuse |
|
|
Zyrun
|
  |
| Joined: 06 Sep 2011 |
| Total Posts: 45 |
|
|
| 21 Oct 2017 06:15 PM |
| I don't exactly know what you mean, but I'm sure something I have to say will help you. For loops are a great way to name instances(parts, models, etc) with numbers. Here is an example that names parts inside of a table Bob with the according number. local Table = {"Part1","ZyrunIsCool","Part","WhoKnows"} for i = 1, #Table, 1 do Table[i] = "Bob"..[i] end print(table.concat(Table, ", ")) Now, In the output we get this: ##### ##### Bob3 |
|
|
| Report Abuse |
|
|
|
| 21 Oct 2017 06:33 PM |
ok thats stupid whoever did first 2.
This will work in real time to rename the things.
local counter = 0;
local function findChild(instance, name, recursive) for _, child in pairs(instance:GetChildren()) do if child.Name == name then counter = counter + 1; return elseif recursive then counter = counter + 1; return findFirstChild(child, name, true) end end end
game.Workspace.DescendantAdded:connect(function(instance) local name = instance.Name; local recursive = true; findChild(instance,name,recursive); instance.Name = name..tostring(counter) counter = 0; end)
i cant test cause studio breaks everytime I exit and come back |
|
|
| Report Abuse |
|
|
|
| 21 Oct 2017 06:35 PM |
local counter = 0;
local function findChild(instance, name, recursive) for _, child in pairs(instance:GetChildren()) do if child.Name == name then counter = counter + 1; elseif recursive then return findFirstChild(child, name, true) end end end
game.Workspace.DescendantAdded:connect(function(instance) local name = instance.Name; local recursive = true; findChild(instance,name,recursive); instance.Name = name..tostring(counter) counter = 0; end)
that might work actully |
|
|
| Report Abuse |
|
|