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 » Scripters
Home Search
 

Re: When to use Local Scripts?

Previous Thread :: Next Thread 
iNicklas is not online. iNicklas
Joined: 26 Oct 2010
Total Posts: 4031
02 Jan 2015 05:33 AM
I'm confused about it. Since i only use "Script", i first learned Lua yesterday, so, im a newb.


3001 R$ / 500,000 R$ - Follow Me On Twitter! @iNicklasRBLX •_•
Report Abuse
DominusAstra is not online. DominusAstra
Joined: 23 Jun 2014
Total Posts: 12468
02 Jan 2015 05:39 AM
To do stuff with the mouse, and other times like... idk I'm not good at examples.
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 05:40 AM
So the important thing to know here is the difference between the two.

A LocalScript exists and runs on a client. (IE you're ROBLOX player application)
A Script exists and runs on the server. (The thing hosting the game you are connected to)

Due to this there are some important things one or the other has access to. For example, the mouse. The mouse only exists on clients, so only LocalScripts can access it. (game.Players.LocalPlayer:GetMouse()) Where as say the DataStore service can only be accessed by the ROBLOX servers, so only a Script can make those calls.

In most cases, LocalScripts are used to handle user input and GUI. Need to know what keys a player is hitting? LocalScript. Need to know where there mouse is pointing? LocalScript. Want to show them something on a GUI? Local script.

Scripts usually run most of a games logic. Did someone touch a door and it needs to open? Script. Did the time run out and all players need to be returned to the lobby? Script. Want to award a badge? Script.
Report Abuse
iNicklas is not online. iNicklas
Joined: 26 Oct 2010
Total Posts: 4031
02 Jan 2015 05:40 AM
^ Its a kind of help so yes :)


3001 R$ / 500,000 R$ - Follow Me On Twitter! @iNicklasRBLX •_•
Report Abuse
iNicklas is not online. iNicklas
Joined: 26 Oct 2010
Total Posts: 4031
02 Jan 2015 05:41 AM
But how come my gui button work with a script, and not a local script. When its mousebutton


3001 R$ / 500,000 R$ - Follow Me On Twitter! @iNicklasRBLX •_•
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 05:44 AM
Because local scripts and server script ('Normal' script = server script) don't work exactly the same

Some things won't work in a local script that work in a server script

And vice versa
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 05:45 AM
Believe it or not Gui Button objects work with BOTH. It's better practice typically to use a LocalScript for all possible instances when working on GUI. (Infact really, all GUI should run LocalScripts only bothering to send data remotely to the server through RemoteEvents and RemoteFunctions, but that's kinda more advanced then a beginner needs to worry about.)

The buttons simply replicate their event to the server. (Which is what a RemoteEvent would do manually) If the Script doesn't work as a LocalScript it's probably because it references things only available to the server.
Report Abuse
iNicklas is not online. iNicklas
Joined: 26 Oct 2010
Total Posts: 4031
02 Jan 2015 05:46 AM
Okay :D


3001 R$ / 500,000 R$ - Follow Me On Twitter! @iNicklasRBLX •_•
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 05:48 AM
Actually 128GB they work exactly the same. They both use the same Lua Interpreter and they even have the same functions exposed to them, they simply toss errors when things are not found. Clients and Servers do not contain the same objects. A perfect example is ServerStorage and the LocalPlayer. A server can attempt to call a LocalPlayer, however that property doesn't exist on the server. The script is doing the exact same thing, it just doesn't find what it's looking for. And if a LocalScript calls ServerStorage, it does the exact same thing, however ServerStorage doesn't exist on the client.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 05:54 AM
Actually no
Some things aren't allowed to be used by local scripts, mostly methods

Like LoadCharacter only works in server scripts


The player added event only works in server scripts

ect
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 05:58 AM
And also the local player property does exist to the server but its a nil value

Just like if you did

local a = Instance.new("ObjectValue")
print(a.Value) -->nil
Report Abuse
liambasnett122 is not online. liambasnett122
Joined: 14 Jan 2015
Total Posts: 29
02 Jan 2015 06:06 AM
A localScript is used for just that player it must be in the player example like animation.
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 06:06 AM
Again, it's not that the scripts are doing anything different. The Lua Interpreter is the same. It's simply that the c++ (I'm pretty sure ROBLOX is a c++ environment, don't quote me) environment kicks back different results.

You're point about the localplayer only furthers my point though. They are not physically different. Their environments are. If a LocalScript tries to call a Server only function, such as LoadCharacter, depending on the enviornment it's either going to:
A) Error because it made a nil call. That function does not exist on the client.
B) Error because the environment housing the script returns an error. (Such as when a LocalScript attempts to call the DataStore and it successfully returns an error that only servers can do that)
C) Successfully make the call and do nothing as the change it not replicated/fails to do anything on a client.

A script not being allowed to do something does not mean the script is different in any way. It's the script's environment. Scripts and CoreScripts are not different. They can make the same calls. They use the same interpreter. However a CoreScript's environment gives it high permissions and thus doesn't return an error saying a function is locked when Roblox tells normal scripts it is.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 03:46 PM
B) Error because the environment housing the script returns an error. (Such as when a LocalScript attempts to call the DataStore and it successfully returns an error that only servers can do that)


That would mean the script doesn't work exactly the same

I don't know why you are bring the interpreter into this

I said they don't work the same, and they don't

Ones on the client, ones the server, thats different

Some are able to use some functions, others aren't (Not that the functions don't exist, but they are not allowed to use them), thats different

One runs in workspace, ServerScriptStorage, and so on, the other doesn't, thats different
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 09:27 PM
That's not a difference in the scripts, it's a difference in their environment. They are the same things, in different environments.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 09:59 PM
'That's not a difference in the scripts, it's a difference in their environment'

You just said 'Its not a difference in the scripts, its a difference in the script'

The script is ran with its environment, so if its using a different one, they don't work the same


I'm not saying its not a script I'm saying they don't do the same things >.>
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
02 Jan 2015 11:08 PM
They really do do the same things though. They run Lua. There is no actual difference in a LocalSCript and a Script and a CoreScript. They are all Lua code that the Interpreter will run through the processor.

The difference is the environment, which has nothing to do with the script. I can take a script from ROBLOX that doesn't use any environmental dependencies and plug it into LOVE, or ComputerCraft. They will do the exact same things, because they are in no way different. Environments are not the same as the objects themselves.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
02 Jan 2015 11:12 PM
In my mind I see things I consider them working differently, maybe I'm wrong, but we are just going back and forth on this
Report Abuse
tycolt3 is not online. tycolt3
Joined: 11 Nov 2012
Total Posts: 27
17 Apr 2016 09:03 PM
This is a bit old, but how could I get information from a local script into a regular script. Or better yet, how can I find the local player and give that information to a regular script. So like, find local player, then print it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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