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: It's been a while since I last scripted so...

Previous Thread :: Next Thread 
Yiha26 is not online. 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
SilverArgentum is not online. SilverArgentum
Joined: 01 Nov 2011
Total Posts: 1162
22 Jul 2014 06:22 PM
script.Parent:Destroy()


might work better?
Report Abuse
Yiha26 is not online. 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 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
22 Jul 2014 06:25 PM
Use destroy or you will get a memory leak :P
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
22 Jul 2014 06:28 PM
You're using the command bar thing. Put it in an actual script maybe...
Report Abuse
cntkillme is not online. 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 is not online. 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
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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 is not online. 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
demonshadow553 is not online. demonshadow553
Joined: 06 Sep 2013
Total Posts: 2626
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
22 Jul 2014 06:35 PM
It happened to one of my GUIs (MouseButton1Down events prevented it from being GC'd)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Jul 2014 06:35 PM
unknown
I actually never thought about that ;c
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
22 Jul 2014 06:36 PM
Neither did I until it happened :(
Report Abuse
demonshadow553 is not online. demonshadow553
Joined: 06 Sep 2013
Total Posts: 2626
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
22 Jul 2014 06:47 PM
Down = down, Click = click, Up = up.
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