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: How to make a simple brick removing script?

Previous Thread :: Next Thread 
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:00 PM
I have weapons that shoot a raycast brick called "lasershot". However, if killed while in mid-firing, the raycast brick remains in the air, forever.

Is there a simple script that can periodically check for all bricks in the workspace named "lasershot", and remove them?
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:11 PM
Well, I don't want to make one for you so here's a hint

"bricknamehere":Destroy()





~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:12 PM
I can make a simple one like that. I'm just wondering:

If there are multiple bricks of that name, will it remove them all?
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:14 PM
I think so. Try it, and report back, sergeant.




~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:17 PM
Nope it will no work.

Try this

w = workspace:children()
for i=1,#w do --it finds how many children the workspace has
if w[i].Name == "NameHere" then --if the part has the name "NameHere" then
w[i]:remove() --it will destroy it
end --ZOMG THE ENDZ

it may be slower by it works smoothly
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 May 2012 07:17 PM
It's probably better to remove them after a certain time after you shoot. So in the shooting script, try adding a wait() function to pause the code, then remove it.
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:17 PM
It can remove the first "lasershot" shot in the workspace. However, if multiple shots are in the workspace, or you get another one glitched after the first is removed, it won't anymore.

I really just need it to do continuous checks.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
21 May 2012 07:19 PM
Well in answer to your question, it depends on what your script is. If you have one script for every gun, and in that script, it has something like:

script.Parent.LASER:Destroy()

then you do not really need to check all in workspace, as it will automatically remove the laser in the object (each script is a different thread).
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:21 PM
I simply want to have *one* script in the workspace, that does continuous checks for "lasershot" bricks in intervals, and removes them, and repeat.
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:23 PM
Just guessing but would "while true do" be useful to you?







~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:25 PM
You can also try this

script.Parent = workspace
while true do
wait(5)
l=script.Parent:findFirstChild("lasershot")
if l ~= nil then
l:remove()
end
end

It searches every 5 seconds for a part named lasershot then deletes it.

Report Abuse
Fizzzzzlemaster is not online. Fizzzzzlemaster
Joined: 07 Jul 2009
Total Posts: 4612
21 May 2012 07:25 PM
I don't think so... Wouldn't that still just delete one of them? And if they fire while it is doing it over and over, the laser would be deleted when it fires.
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:25 PM
Thats how I would've initiated the script.

Here's what I've come up with myself:


while true do
wait(1)
script.Parent.lasershot:Destroy()
end
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:27 PM
Then it would have been working when there isn't a lasershot in the workspace.




~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:29 PM
I'm not the best in this category.

Would using GetChildren() be of use?
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:31 PM
I don't think so, unless you explain where you would you would be finding the Childre of.






~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:31 PM
LOL i just realized this: Why wont you make a script that every time you shoot a laser, it clones another script that destroys its own parent after the desired amount of time? Like:

wait(5)
if script.Parent:isA("Part") then
script.Parent:destroy()
end
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
21 May 2012 07:33 PM
Well, that just solved our problem, I guess.





~Let the Flame Wars begin! And may the odds NEVER be in your favor!~
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
21 May 2012 07:33 PM
How about adding a brick remover script?

So create a script, and DISABLE IT. Then inside it put this:

----
wait(10)
script.Parent:Destroy()
----

And then in your code, parent that script to the bullet, and set the disabled to false. That way it'll work!
MrMcAero
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:35 PM
@Mr
My script will work exactly like yours but it doesnt need to be disabled because it will only delete its parent if it is a Part.
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:36 PM
You'll have to elaborate. You guys are going a tad over my head.
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:38 PM
What do you mean? :P If you cant do it by yourself, just put part of the code where it makes the laser, here. Ill edit it.
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:42 PM
But really guys:

while true do wait(5)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "lasershot" then v:remove() end
end
end

That works just fine.
Report Abuse
vampirexevipex is not online. vampirexevipex
Joined: 11 Apr 2009
Total Posts: 1598
21 May 2012 07:45 PM
It will happen what Fizz said:

"If they fire while it is doing it over and over, the laser would be deleted when it fires."

Use mine -_-
Report Abuse
MasterDesigner is not online. MasterDesigner
Joined: 07 Mar 2010
Total Posts: 3915
21 May 2012 07:48 PM
"wait(5)"
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