Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:32 AM |
| Is it possible to access the object being touched in this method? I know you can pass in the object touching the original object, however I am not running this script in the object being hit so I can't use script.Parent. Any ideas? |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
| |
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 04:34 AM |
| The only way to connect this event to a function is to access the object being touched, shouldn't you already have access to it? |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 04 Jun 2014 04:35 AM |
function FUNCTIO _NAME(hit) hit:Destroy() <- object that touched it end
script.Parent.Touched:connect(FUNCTION_NAME) |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:36 AM |
I'm attempting to globalize a pickup script so I don't need one in every pickup.
pickup = Instance.new("Part") pickup.Touched:connect(function(object, pickup) --stuff happens here end) |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:37 AM |
| I am aware the above example does not work, however when I reference pickup without trying to pass it in it is nil, give me a second and I will post you a working broken example. :) |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
| |
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:38 AM |
| Actually ignore this, it seems like I am referencing it just fine, there must a problem in some of the code inside the onTouched method. Thanks for the help anyhow! |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:40 AM |
| I now see what it was doing, each time I generated a new pickup and connected the function it was using the new pickup in EVERY connect function. |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 04:44 AM |
| That could be remedied through the use of tables, however I'm sure you've already done so. |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:45 AM |
I went back to the copying the script out of lighting method. Not the best way I know but unless they change the Touched event to the following it's no use as I planned:
Touched ( BasePart thisPart, BasePart otherPart ) |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:46 AM |
| I thought about that nomer888, but decided against it as I really don't want to have to move the pickup out of the table once it has been used. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 04 Jun 2014 04:47 AM |
Part.Touched:connect(hit) Part - Hit
U should know when you connected the line. |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:49 AM |
| vlekje513 I had a scoping issue with the part as the function was getting repeatedly called using a different part each time the old connections didn't have a local copy of the pickup which meant that they also used the new pickup. |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 04:50 AM |
| Perhaps you could insert the variable defined to create the pickup into a table, then connect the desired function to pickuptable[#pickuptable]? |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 04:51 AM |
| Whoops, sorry, didn't see the posts before mine while writing it. |
|
|
| Report Abuse |
|
|
Shaakra
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 1464 |
|
|
| 04 Jun 2014 04:53 AM |
nomer888: But then I have to do more maintenance on the table or let it grow continuously. I wanted a one off function call that cleaned up after itself nicely that could be used without having to clone in a new script for each object.
After considering my options I'm going to use the cloned script approach as it's safer than having one point of error. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 04 Jun 2014 04:56 AM |
Destroy disconnects all connections.
A table is the use for this. table.remove() |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 05:33 AM |
I tried this in Studio, and it seems to be doing what I believe you want:
function makePickup() local pickup = Instance.new("Part") pickup.Touched:connect(function() pickup:Destroy() end) end
It of course requires some necessary property modifications (position, parent, etc), but when called multiple times to spawn multiple parts it deletes whatever is touched properly and without error. |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 04 Jun 2014 05:46 AM |
| how do u have a place with 3 mil visits without knowing this. |
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 05:51 AM |
| Shaakra was asking something a lot of people would be bottlenecked on. Not every famous person knows every single in and out of everything. |
|
|
| Report Abuse |
|
|
|
| 04 Jun 2014 05:57 AM |
If you want to access the touched part, script.Parent Otherwise.. hit |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 04 Jun 2014 06:02 AM |
I misinterpreted the question. This is actually a fairly advanced question, and it's fair that he would ask this.
but know that you can do this
local model = workspace.Tower1 for i, v in pairs(model:GetChildren()) do
v.Touched:connect(function(hit) v:Destroy() end) --would result in only destroying the part that was hit end
|
|
|
| Report Abuse |
|
|
nomer888
|
  |
| Joined: 13 Feb 2010 |
| Total Posts: 551 |
|
|
| 04 Jun 2014 06:06 AM |
| You can do that, but when (in Shaakra's case) a new pickup is made and that for loop runs, all of the children within that model are being connected again, resulting in a buildup of multiple connections. |
|
|
| Report Abuse |
|
|
Waffloid
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1606 |
|
|
| 04 Jun 2014 08:37 AM |
function Touched(hit) print(hit.Parent) -- The object that touched the brick that it is connected to. end
~I'm not crazy, the voices in my head said so!~ |
|
|
| Report Abuse |
|
|