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 » Scripting Helpers
Home Search
 

Re: Removing all of something?

Previous Thread :: Next Thread 
Shagabash is not online. Shagabash
Joined: 20 Jun 2008
Total Posts: 6217
30 Dec 2011 08:20 PM
Hi, I'm an amateur scripter, lol.

I'm familiar with basic functions like :remove()

But, how do I remove all of something? For example I'm going to have a bunch of balls that are named "Ball". I want them to be all removed at once.

This is probably really easy, but, I didn't find it on the wiki (maybe didn't look hard enough).

Help?
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
30 Dec 2011 08:21 PM
for i, v in pairs(Workspace:GetChildren()) do
if v.Name=="Ball" then
v:remove()
end
end
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
30 Dec 2011 08:21 PM
for _, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Ball" then
v:Destroy()
end
end


:Destroy() is better than remove.

This will destroy all objects in the workspace that are named Ball
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
30 Dec 2011 08:21 PM
@Bio
I don't get that. What does i, and v represent?
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
30 Dec 2011 08:23 PM
@Bio

i is the first loop variable representing the number the loop is on.
v is the object the loop is currently "looking at", a little hard to describe.

They can be named anything.
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
30 Dec 2011 08:24 PM
@Me

You're stupid, you replied to the guy that the guy you were trying to reply to was replying to. Next time think things out more!
Report Abuse
Shagabash is not online. Shagabash
Joined: 20 Jun 2008
Total Posts: 6217
30 Dec 2011 08:24 PM
Thanks, it worked.

Also.. might I ask why :remove() isn't as good as :Destroy()?
Report Abuse
linkskills is not online. linkskills
Joined: 12 Jun 2010
Total Posts: 6642
30 Dec 2011 08:24 PM
You would have to say it as a Variable than.
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
30 Dec 2011 08:25 PM
In the pairs loop, the first argument is the index. Every time it reiterates(if that's a word) it will add one to it. V is the item in the list under the index i. So, this would print the value of i.
for i, v in pairs(game.Workspace:GetChildren()) do
print(i)
end

If there are four children of workspace, you would get this in your output.
1
2
3
4


Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
30 Dec 2011 08:26 PM
They don't have to be i and v.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
30 Dec 2011 08:27 PM
But where does i v get their values?
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
30 Dec 2011 08:29 PM
What Destroy does:

Sets the objects parent to nil
Locks the objects parent
Frees up the memory taken by the object
Calls Destroy on all objects inside of the object

What Remove does:

Sets the objects parent to nil
Calls Remove on all objects inside of the object



You can also do:

object.Parent = nil

If you want to remove the object for a little bit so you can bring it back later in tact the way it left.
Report Abuse
Biostream is not online. Biostream
Joined: 28 Mar 2011
Total Posts: 913
30 Dec 2011 08:32 PM
When using a pairs() loop, you have to specify the list to iterate through, and the variable that the current object will be named, and the number that will be used as the index. i, which is normally the first argument, will be the index. The index always starts at one and adds one to itself every time. V is the object in the list under i index.

numbers={4, 5, 6}--this is my list

for i, v in pairs(numbers) do--you must specify the list, and two variables
print(i)--i is the index, so you will get 1, 2, 3
print(v)--v is the object in the list under the index of i, so the 1st object in the list numbers is 4, the 2nd is 5, and the 3rd is six, so the output will be 4, 5, 6
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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