Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 10:47 PM |
| I'm trying to manipulate a value within a localscript inside the player. But the value inside the localscript is always nil when I try to access it using the script. Is this supposed to happen? |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 10:50 PM |
Be more descriptive. Post the script please.
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 10:52 PM |
character>localscript >IntValue
localscript: print(script.IntValue) --> nil |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 10:53 PM |
Is there another program that acesses IntValue? Are you sure it's named IntValue?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 10:54 PM |
Sorry. That'll return an error saying 'IntValue is not a valid member of localscript'. print(script:FindFirstChild("IntValue")) will return 'nil' |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 10:54 PM |
print(script.IntValue.Value)
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 10:54 PM |
| The error only occurs in online play. Solo mode works fine. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 10:55 PM |
... I've been gone too long, totally forgot that .Value is needed :P
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 10:55 PM |
*Me. No, just no. I'm checking to see if the instance exists within the parent. Nothing to do with it's value. |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
| |
|
|
| 11 Aug 2013 10:58 PM |
@Sehnsucht I probably should have noticed that.
Anyways, add this before doing anything using that Value inside your script:
repeat wait() until script:FindFirstChild("IntValue")
The reason you need to do that is that when a Script/LocalScript is added to the game, it runs right away. This means that objects within the script may not have been loaded yet. However, if you wait for them to load, you should be okay.
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 11:00 PM |
| The intvalue isn't added, it's always parented to the localscript. And the localscript isn't run until well after the game is started. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 11:02 PM |
Post the full script.
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 11 Aug 2013 11:05 PM |
As odd as the situation is, waiting until the IntValue was found worked. I'm baffled though, since the Value is parented to the script to begin with and the script isn't undisabled until 5 minutes in game.
Thankyou for the advice. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2013 11:23 PM |
| LocalScripts run on the client, so I'm guessing when you un-disable the LocalScript (I'm assuming you re-parent it as well) via Script, the LocalScript runs before the IntValue is even registered to exist via the server. |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 12 Aug 2013 12:35 AM |
| @Mike, that was exactly the issue. When I take the whole script and instance together and re-parent it, the script runs before the instance parented to it is even loaded. It was only a problem with a localscript on a online server, however. Regular server side scripts worked fine with the same exact method. |
|
|
| Report Abuse |
|
|
|
| 12 Aug 2013 01:09 AM |
| That's because regular scripts in solo mode don't *really* act server-side. |
|
|
| Report Abuse |
|
|
Sehnsucht
|
  |
| Joined: 10 Apr 2011 |
| Total Posts: 990 |
|
|
| 12 Aug 2013 01:29 AM |
@Mike, Even in Online Play regular scripts didn't appear to have that problem and worked fine. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 12 Aug 2013 01:37 AM |
Here's how things work server-side:
1. Game gets loaded 2. Scripts start to work
Here's how things work client side:
1. Game gets loaded 2. Player gets character loaded 3. Stuff gets copied in PlayerGui/Backpack
In step 3, note that LocalScripts have an uncanny ability to run as soon as they're runnable, which might be before the PlayerGui or Backpack is fully loaded, whereas in step 2 of the first list, the game gets fully loaded and THEN the scripts run.
Roblox also doesn't know when exactly to run LocalScripts, so it figures that it can get away with running it as soon as possible (which it can't). So, for now just use WaitForChild. |
|
|
| Report Abuse |
|
|