VoidHack Expert Scripter


Posts: 42 Join date: 2010-08-02 Age: 19 Location: Rhode Island, United States of America
 | Subject: LocalParts August 8th 2010, 6:01 pm | |
| Okay, a LocalPart is a part that only one player can see. (This is going to be annoying to make super simple...) These parts MUST be created using ONLY a LocalScript. To avoid annoying-to-edit spaghetti (really messy) code, I suggest building the object where you like it, then placing it into the Lighting service. Then just clone it. Anyways, you need to use a LocalScript, meaning you can place it in either the StarterPack or the StarterGear, so it will always go into the player in some way. Or you can always clone it in, but that isn't fun. Now, time to script. LocalParts need to be placed into the CurrentCamera object in Workspace. This is why a LocalScript is needed. To access the camera, you need the LocalScript. That is the only reason for it. | Spoiler: | | | I took a dinner break xD | Now, (if you read the spoiler, you would know why I said now) With LocalParts, though, the touched event will NOT work. Instead you need a different event, named .LocalSimulationTouched. This event works like .Touched, though, it only works for LocalParts, and it only works for the player the LocalPart belongs to. (I'm getting bored about now...) So, time for code. In this example, there will be a model in Lighting named LOCAL_TEST. This model will be cloned into the CurrentCamera. In the model will be a part named Button. When this is touched, a message will appear.
| Code: | local Model = game.Lighting.LOCAL_TEST:Clone() Model.Parent = game.Workspace.CurrentCamera |
In this, we took LOCAL_TEST and created a copy of it, then we placed it into the CurrentCamera. Now, we need to create a LocalSimulationTouched event for the Button. For this we will use an annoymous function, which has no name to it. The connection also comes BEFORE the function, rather than after. If you become advanced later on, you will learn to love these =P
| Code: | Model.Button.LocalSimulationTouched:connect(function(Hit) |
This creates the event. Now to make a message in the player. We will set the text as "You have touched a LocalPart". Then we will remove the Part. Now, there are two ways to set an Instance'd object. The first is a simpler way. The second is faster and shorter, though. I will add the second way in comments, though, the first way will be the way run.
| Code: | local Message = Instance.new("Message") --local Message = Instance.new("Message", game.Players.LocalPlayer) --Now, this way, the parent becomes the second argument of the function. --It is more advanced, kinda. You don't need to set .Parent, --using this, though Message.Parent = game.Players.LocalPlayer Message.Text = "You have touched a LocalPart" wait(3) --Wait 3 seconds Message:Remove() --Remove the message Model.Button:Remove() --Remove the button end) --End the function |
Now, that is the script. In chunks. We can make it all together, and it will look a little different. Though, then you can just copy and paste it and use the same model instructions as the example. Then you learn nothing. So, I will place it in a spoiler, if you read this, you will know that.
| Spoiler: | | | | Code: | local Model = game.Lighting.LOCAL_TEST:Clone() Model.Parent = game.Workspace.CurrentCamera Model.Button.LocalSimulationTouched:connect(function(Hit) local Message = Instance.new("Message") --local Message = Instance.new("Message", game.Players.LocalPlayer) --Now, this way, the parent becomes the second argument of the function. --It is more advanced, kinda. You don't need to set .Parent, --using this, though Message.Parent = game.Players.LocalPlayer Message.Text = "You have touched a LocalPart" wait(3) --Wait 3 seconds Message:Remove() --Remove the message Model.Button:Remove() --Remove the button end) --End the function |
|
**PLEASE INFORM ME OF ALL ERRORS IN THIS IF ANY** |
|
Prodigy Administrator

Posts: 58 Join date: 2010-07-28
 | Subject: Great tutorial August 8th 2010, 6:56 pm | |
| This is a great tutorial and will come in handy for many different things. The main use for this tutorial would probably be a question/quiz game. |
|
VoidHack Expert Scripter


Posts: 42 Join date: 2010-08-02 Age: 19 Location: Rhode Island, United States of America
 | Subject: Re: LocalParts August 8th 2010, 7:03 pm | |
| I feel my commentry is all in order :3 |
|
VoidHack Expert Scripter


Posts: 42 Join date: 2010-08-02 Age: 19 Location: Rhode Island, United States of America
 | Subject: Re: LocalParts August 8th 2010, 9:24 pm | |
| | Prodigy wrote: | | This is a great tutorial and will come in handy for many different things. The main use for this tutorial would probably be a question/quiz game. | I actually based a game section around this. I used LocalParts to make my doors (well, gates) to lock a LongBow in a cage. Then when you press a LocalButton, it opens the gate. |
|
blueymaddog Administrator


Posts: 1108 Join date: 2010-12-09 Age: 13
 | Subject: Re: LocalParts January 18th 2011, 4:15 am | |
| Nice tutorial! almost belongs to intermediate tutorials. _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> |
|