Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 06 Nov 2012 08:55 AM |
| How would i delete an object that the name starts with "Map", the name isnt map its Map1 and Map2, but i want to delete everything that starts with Map, its something about string.sub right? |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 06 Nov 2012 09:01 AM |
T = workspace:GetChildren() for i = 1, #T do if T[i]:sub(1, 3):lower == "map" then T[i]:Destroy() end end
try this, it should work. |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 06 Nov 2012 09:03 AM |
Would work, but you forget to get the name T[i].Name
for k,v in pairs(Workspace:GetChildren()) do if v.Name:lower():sub(1,3) == "map" then v:Destroy() end end |
|
|
| Report Abuse |
|
|
|
| 06 Nov 2012 09:27 AM |
Lol just do this
for _,v in pairs(workspace:GetChildren()) do if string.match(v.Name, "map") then v:Destroy() end;end |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 06 Nov 2012 10:17 AM |
| @Death, does string.match match words or also letters, because if not that will delete "map" and not map that starts with map. |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 06 Nov 2012 10:55 AM |
| No, match uses regular expressions, to delete just map you use the pattern "^map$" with "map" it returns if the string contains "map" like "adsadsmapasa" or "map1" |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 06 Nov 2012 11:02 AM |
| Woops, I did totally noob out and forget T[i].Name, well my works just throw in the .Name before :sub(1, 3) and it will work for you. But don't use match, it could potentially delete things you don't want it to. |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 06 Nov 2012 11:07 AM |
| ^A lot of people prefer sub over match, even for commands. I prefer to use match, if you are good with regular expressions you shouldn't get unexpected results. |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 06 Nov 2012 11:14 AM |
| Well I try to give out things that are sure to work, though frankly match is better to use in general if it doesn't matter where the word appears. I use sub alot though for things such as my linux terminal emulator(Derpbian, best and only linux emulator on Roblox) and my chat system at samurai feud III(Corrects grammar to an extent, and bans noobs ;) ) so it is more a force of habit for me to go with sub rather than match. |
|
|
| Report Abuse |
|
|