What Is A Local Part?
Roblox Studio uses what is called a client server architecture. This means that when a game runs it is actually created in 2 places. The server is the version that everybody in the game is a part of and the client is the device or computer that you experience the game on. When things happen on the server or the client they are copied or replicated between the two with some exceptions.
An example of a local object is usually a menu GUI that might pop up when a player clicks a button. This happens only on the players client machine because it is only relevant to that player. It would be pretty annoying if a pop up menu appeared for everybody anytime a player pressed the menu button!
Using the same logic it is a very powerful concept to create local parts that are only relevant to the players you as a developer want to effect. An example is a door or gate that is solid for players that can not enter an area, but disappears for other players that are allowed to enter. So a local part is one that only effects specific players on their client machines or devices.
Using RunContext On Scripts
I created a project to demonstrate the use of RunContext and how it effects the parts that the script is attached to. The image above shows two parts that have been created in the workspace. They are named localPart, and serverPart.
I created one Script with the following code in the serverPart then duplicated the script and moved it into the localPart. If you study the image to the right you can see that I have clicked on the Script in the localPart then in its properties under Behavior I have changed the RunContext to be Client.
What Does It Do?
Remember that the same code is running for each part. The difference is that by changing the RunContext of the Script in the localPart to Client we have made that Script behave just like a Local Script, which will not run on the server side. Only Script has the property RunContext, you will not see it if you create a LocalScript.
What you are seeing when you run this project is that both parts are affected by the code on the client. They both change their transparency and disappear. On the server side however only the serverPart is effected by the script that is running. The localPart remains unaffected.
Code for serverPart and localPart
local part = script.Parent local function ShowPart() if part.Transparency == 0 then part.Transparency = 1 else part.Transparency = 0 end task.wait(5) ShowPart() end ShowPart()
How Can I Use It?
If we use a locked door as an example. The player must find a key before they are able to unlock the door and move forward. The door part would contain the a Script with RunContext set to Client. You would then write code to check if the player had a key when they touched the door. If so you can open or destroy the door just for that player. The door on the server will remain in place for all other players.
I’m sure you can find lots of other uses for local parts if you put your mind to it. I hope you found this useful :)