Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 02:15 PM |
How do I make a part change a property (of my choice) of any part that is touching the part.
So basically what do I need to do/learn to make for example, make a part that destroys anything that touches it. Even if it's being touched by another part already.
I know how to make a part destroy other parts using this
=========================================== function DIEPART(hit) hit:Destroy() end
script.Parent.Touched:connect(DIEPART) ============================================
but the problem is using this script the part will not destroy other parts that are already touching it once I load up the game.
Hope somebody can help
thanks in regards |
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 02:16 PM |
| I'm thinking i might need to use an "if" statement to do this but i'm not sure |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 02 Sep 2016 02:16 PM |
Because if the part is already touching, it won't fire the event. You need to move the parts again for the event to fire.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 02 Sep 2016 02:17 PM |
However you could always see what parts are touching by using a handy function:
part:GetTouchingParts()
this will return a table of all the parts that are currently touching the part
|
|
|
| Report Abuse |
|
|
|
| 02 Sep 2016 02:20 PM |
local parts = {} local ins = table.insert local part = workspace.Part
ins(parts,part:GetTouchingParts())
|
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 02:31 PM |
I'm a noob and i tried this
local parts = {"Yo","Part"} local ins = table.insert local part = workspace.Part
ins(parts,part:GetTouchingPartsDestroy())
but doesn't work and can't figure it out but ill keep trying. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2016 02:36 PM |
local parts = {} local ins = table.insert local part = workspace.Part local touched = false part.Touched:connect(function(hit) touched = true end) part.TouchEnded:connect(function(hit) touched = false end) ins(parts,part:GetTouchingPartsDestroy())
repeat wait() until not touched
for _,v in ipairs(parts()) do if game.Workspace:FindFirstChild(v) then local P = game.Workspace[v] P:Destroy() end end
|
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 02:39 PM |
Thanks for the help but that is too complicated for my knowledge at the moment is there a simpler way to do it or can you at least explain it so i understand because I just tried it
local parts = {} local ins = table.insert local part = workspace.Part local touched = false part.Touched:connect(function(hit) touched = true end) part.TouchEnded:connect(function(hit) touched = false end) ins(parts,part:GetTouchingPartsDestroy())
repeat wait() until not touched
for _,v in ipairs(parts()) do if game.Workspace:FindFirstChild(v) then local P = game.Workspace[v] P:Destroy() end end
but it doesn't work and i don't know why not. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2016 02:42 PM |
local parts = {} -- table of parts local ins = table.insert -- table.insert local part = workspace.Part -- the part that gets hit local touched = false -- touched local part.Touched:connect(function(hit) -- touch started touched = true -- sets touched as true end) ins(parts,part:GetTouchingPartsDestroy()) -- inserts every touched parts into the parts table part.TouchEnded:connect(function(hit) -- touch ended, sets touched as false touched = false end) repeat wait() until not touched -- waits until finished touching
for _,v in ipairs(parts()) do -- scans parts if game.Workspace:FindFirstChild(v) then -- checks if v is a member of workspace local P = game.Workspace[v] P:Destroy() -- destroys it end end
|
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 02:52 PM |
local parts = {"Part","Yo"} -- table of parts local ins = table.insert -- table.insert local part = workspace.Part -- the part that gets hit local touched = false -- touched local part.Touched:connect(function(hit) -- touch started I don't know what to do here??? touched = true -- sets touched as true end) ins(parts,part:GetTouchingPartsDestroy()) -- inserts every touched parts into the parts table part.TouchEnded:connect(function(hit) -- touch ended, sets touched as false touched = false end) repeat wait() until not touched -- waits until finished touching
for _,v in ipairs(parts()) do -- scans parts if game.Workspace:FindFirstChild("Part","Yo") then -- checks if v is a member of workspace local P = game.Workspace["Part","Yo"] P:Destroy() -- destroys it end end
|
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
| |
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
|
| 02 Sep 2016 03:03 PM |
| Also noting i'm not using filtering enabled |
|
|
| Report Abuse |
|
|
Tobycon
|
  |
| Joined: 22 May 2013 |
| Total Posts: 1527 |
|
| |
|
|
| 02 Sep 2016 03:57 PM |
| lmao this started out super simple but then these guys blew it out of proportion |
|
|
| Report Abuse |
|
|