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: So I'm bad with for loops.

Previous Thread :: Next Thread 
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 06:52 AM
I'm bad at using for loops, so I am trying to practice using them, I don't know what is wrong with this.

local ingame = Workspace:GetChildren()

for i,v in pairs(ingame) do
if ingame.Name~=Spawn then
ingame:Delete()
end
end
Report Abuse
alij12 is not online. alij12
Joined: 03 Oct 2011
Total Posts: 1204
26 Jul 2014 06:53 AM
>:Delete() isnt a real method

try this:

local ingame = game.Workspace:GetChildren()

for i,v in pairs(ingame) do
if v.Name~= "Spawn" then
v:Destroy()
end
end
Report Abuse
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 06:54 AM
Changed the code a little bit, I've tested and it just disconnects the event I've attached it to.


local kids = Workspace:GetChildren()

for i,v in pairs(kids) do
if kids[i].Name~=Spawn then
ingame[i]:Delete()
end
end
Report Abuse
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 06:56 AM
Oh man, I fixed it and it sends the camera flying away from the spawn, but doesn't destroy anything.
Report Abuse
alij12 is not online. alij12
Joined: 03 Oct 2011
Total Posts: 1204
26 Jul 2014 06:58 AM
first off
dont do
:Delete()
do
:Destroy()
also, for i,v in pairs(kids) do
(kids) is the objects youre getting
if you want to edit those objects you do something like
v:Destroy()

and use this:

local kids = game.Workspace:GetChildren()

for i,v in pairs(kids) do
if v.Name~=Spawn then
v:Destroy()
end
end
Report Abuse
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 07:00 AM
So I changed it so it doesn't delete anything I don't want to... except, the player itself.


Should I use GetPlayers like this

for i,v in pairs(kids) do
if kids[i].Name~=game:GetPlayers
end
Report Abuse
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 07:08 AM
Sorry, I posted an older version of the script that had :Delete instead of :Destroy. Fail me.

How would I not delete the players, because they are all Children of Workspace?
Report Abuse
fret13103 is not online. fret13103
Joined: 15 Mar 2010
Total Posts: 881
26 Jul 2014 07:28 AM
Did it guys...

This is the code.


for i,c in pairs(players) do
for i,v in pairs(kids) do
if v.Name~="Spawn" and v.Name~="Camera" and v.Name~="Instance" and v.Name~="Terrain" and v.Name~="Pos" and v.Name~=c.Name then
v:Destroy()
end
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
26 Jul 2014 07:31 AM
What are you trying to do?
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