generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to make an accumulator but for words?

Previous Thread :: Next Thread 
DrDeath_GamingYT is not online. DrDeath_GamingYT
Joined: 25 Dec 2016
Total Posts: 119
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 is not online. 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 is not online. 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
TheCoderOfLua is not online. TheCoderOfLua
Joined: 12 Apr 2016
Total Posts: 1599
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
TheCoderOfLua is not online. TheCoderOfLua
Joined: 12 Apr 2016
Total Posts: 1599
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image