Yiha26
|
  |
| Joined: 16 Jul 2012 |
| Total Posts: 6117 |
|
|
| 22 Jul 2014 06:21 PM |
I forgot most of it =(
This here does not work:
function onTouched(hit) game.Workspace.Energy.Value = game.Workspace.Energy.Value + 1 wait(.1) script.Parent:remove() end script.Parent.Touched:connect(onTouched)
Fix pls? c: |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:22 PM |
script.Parent:Destroy()
might work better? |
|
|
| Report Abuse |
|
|
Yiha26
|
  |
| Joined: 16 Jul 2012 |
| Total Posts: 6117 |
|
|
| 22 Jul 2014 06:24 PM |
This is what Output says now:
> function onTouched(hit) game.Workspace.Energy.Value = game.Workspace.Energy.Value wait(.1) script.Parent:Destroy() end script.Parent.Touched:connect(onTouched) 01:23:33.490 - function onTouched(hit) game.Workspace.Energy.Value = game:6: attempt to index global 'script' (a nil value) 01:23:33.491 - Stack Begin 01:23:33.492 - Script 'function onTouched(hit) game.Workspace.Energy.Value = game', Line 6 01:23:33.494 - Stack End |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 22 Jul 2014 06:25 PM |
| It seems fine, is this script in a part? and does Energy exist in Workspace? |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:25 PM |
| Use destroy or you will get a memory leak :P |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:28 PM |
| You're using the command bar thing. Put it in an actual script maybe... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 22 Jul 2014 06:31 PM |
'Use destroy or you will get a memory leak :P' No you won't, but events associated with the object won't be disconnected which is basically the biggest reason for destroy.
If you use remove and have no reference, the GC will get it for you. |
|
|
| Report Abuse |
|
|
Yiha26
|
  |
| Joined: 16 Jul 2012 |
| Total Posts: 6117 |
|
|
| 22 Jul 2014 06:32 PM |
@Screw It is in an actual script, I'm not THAT dumb :P
@cnt Yep Energy is in Workspace and the script is in a part. |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:33 PM |
I'm just reading the output:
-there's a ">" at the beginning
-it says attempt to index global 'script' (a nil value)
|
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:34 PM |
| @cntkillme: The connection counts as a reference, causing the object to be kept in memory until it is disconnected. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 22 Jul 2014 06:34 PM |
Are you sure you never did something like:
script, script = nil local script, local script = nil
or something like that |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:35 PM |
So here I rewrote the script:
function onTouched(hit) game.Workspace.Energy.Value = game.Workspace.Energy.Value +1 wait(1) script.Parent:Destroy() end script.PArent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:35 PM |
| It happened to one of my GUIs (MouseButton1Down events prevented it from being GC'd) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 22 Jul 2014 06:35 PM |
unknown I actually never thought about that ;c |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:36 PM |
| Neither did I until it happened :( |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:46 PM |
| Is it MouseButton1Down or MouseButton1Click. Cuz I have recently been using MouseButton1Click for run GUIs and that kind of GUI |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2014 06:47 PM |
| Down = down, Click = click, Up = up. |
|
|
| Report Abuse |
|
|