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: brick destroy on touch

Previous Thread :: Next Thread 
kingstarwest is not online. kingstarwest
Joined: 15 Aug 2010
Total Posts: 1156
30 Mar 2014 11:51 AM
I mean this should be really simple but I thought this would work..

function onTouch()
Part:Destroy()
end

Okay so, what did I do wrong?
Report Abuse
spearman2 is not online. spearman2
Joined: 28 May 2010
Total Posts: 2938
30 Mar 2014 11:54 AM
Part = script.Parent

function onTouch()
Part:Destroy()
end

Part.Touched:connect(onTouch)
Report Abuse
BlackBucketBoy is not online. BlackBucketBoy
Joined: 22 Jul 2011
Total Posts: 3230
30 Mar 2014 11:54 AM
script.Parent.Touched:connect(function(hit)
script.Parent:Destroy()
end)

This script will destroy the Part when anything touches it.
Report Abuse
BlackBucketBoy is not online. BlackBucketBoy
Joined: 22 Jul 2011
Total Posts: 3230
30 Mar 2014 11:55 AM
But if you want it to be destroyed when a player touches it;

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
script.Parent:Destroy()
end
end)
Report Abuse
kingstarwest is not online. kingstarwest
Joined: 15 Aug 2010
Total Posts: 1156
30 Mar 2014 11:59 AM
Thanks to the both of you! Still trying to learn Lua :P



-thread closed-
Report Abuse
kingstarwest is not online. kingstarwest
Joined: 15 Aug 2010
Total Posts: 1156
30 Mar 2014 12:23 PM
Woops before I #endthread

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
wait(2)
script.Parent:Destroy()
end
end)

As you can see in the script I added a wait(2) there so it doesn't destroy straight away but how do I add another if statement? I want a variable called game and if game = true then it will get rid of the part but if it's not then it won't?

Report Abuse
kingstarwest is not online. kingstarwest
Joined: 15 Aug 2010
Total Posts: 1156
30 Mar 2014 12:34 PM
OMG I actually did a script by myself XD

game = false

script.Parent.Touched:connect(function(hit)
if game == false then
if hit.Parent:findFirstChild("Humanoid") then
wait(2)
script.Parent:Destroy()
end
end
end)

check me out lol
Report Abuse
kingstarwest is not online. kingstarwest
Joined: 15 Aug 2010
Total Posts: 1156
30 Mar 2014 12:35 PM
I mean like I had no idea how to add conditions, I just was inserting random stuff and following the errors and it worked :D
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