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 do you use a Local script?

Previous Thread :: Next Thread 
PuNiShEr5665 is not online. PuNiShEr5665
Joined: 12 Aug 2009
Total Posts: 33713
17 Feb 2015 07:48 PM
?
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
17 Feb 2015 07:49 PM
LocalScripts differ from regular Scripts as they do not run server-side, but instead, perform their actions on the client. This makes them incredibly useful for accessing the properties of certain objects which may only appear on the client and not the server, such as a player's Camera. In a LocalScript, using the LocalPlayer property of the Players service will give you the player that has the script, which is the LocalPlayer. For example, in a LocalScript, if you have this code, then the player will be killed.

In order for a LocalScript to function, it must be placed within one of three areas:
In a player's Backpack (can be indirectly, through a Tool or HopperBin)
In a player's character model
In a player's PlayerGui

(Note: a LocalScript does not need to be directly within one of these places, but must at least be a descendant of them, for example, a LocalScript inside a Tool inside their Backpack.)

If a LocalScript is not inside one of these locations, it will not run its Lua code. See Scripting for information about creating custom scripts.

(Source: http://wiki.roblox.com/index.php?title=Local_script)

Go there ^

"I like to program." - Bosswalrus
Report Abuse
PuNiShEr5665 is not online. PuNiShEr5665
Joined: 12 Aug 2009
Total Posts: 33713
17 Feb 2015 07:50 PM
thanks Bosswalrus!
Report Abuse
Bitwyl is not online. Bitwyl
Joined: 15 Nov 2014
Total Posts: 7276
17 Feb 2015 07:52 PM
short and sweet version, for player services mostly
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
17 Feb 2015 07:52 PM
LocalScripts are usually used for accessing the Player(From my experience).

"I like to program." - Bosswalrus
Report Abuse
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
17 Feb 2015 07:55 PM
Using a local script allows you to easily access the properties of certain objects which may only appear to the client and not the server. A great example is the 'Camera'. If you want to adjust only that local clients camera; you'd use a localscript. Also, it makes it much more of ease to monitor one player.

For example; You can do something such as:

context = game:GetService("ContextActionService")
plr = game.Players.LocalPlayer or game.Players.LocalPlayer:wait()

context:BindActionToInputTypes(
"spacy",
function() print(plr.Name, " hit spacebar!"),
false,
Enum.KeyCode.Space)


As you might be able to see from the above; it allows us to also check when individual players interact with the game. We can successfully (and more efficiently) make changes to a characters game experience based on what they do.

Local scripts are great for being able to monitor over individual people and making changes visible to them.
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