Local Parts
What are Local Parts?
Local parts are just regular parts that are recognized by a single player. This can be utilized for a variety of different uses, such as walls that only block certain players, or platforms that will hold players. They, however, will not react to any server objects such as superballs, rockets, or NPC (Non playing Characters) Humanoids.
Another property of local parts is that due to their nature, they inherently respond faster. If you are worried about server lag giving delay to your reset tool's color explosion thing, you can use local parts to do the animation.
A few cautions about Local Parts
Another thing to note is that scripts, local or not, will not run inside the Camera. This could make parts that react exceedingly difficult to code, however, there are certain techniques to get around this.
Local part physics may behave unexpectedly.
Two types of Local Parts
If you're wondering how local parts work, they work because certain objects aren't replicated to the ROBLOX server. If you've ever tried making a Message for a single player, you may see a warning in the output window that says "replication illegal instance." Local parts utilize the fact that Messages don't replicate to the server in order to keep the parts local to the client's computer only.
The first type of local part, as I've just explained, are ones inside a Message instance, inside the player's character. The advantage of these parts is that, due to the fact that they're inside the character, they will not be targets of the player's mouse. This can be used to make unique mouse cursors out of bricks.
The second type of local part goes inside the player's camera. This is the location of choice if you want to allow the user to select the part using a tool or click on it without a tool equipped to walk.
How to make your own Local Parts
In order to make local parts, you need to use a LocalScript. Because local parts get reset every time the player spawns, a LocalScript will have to be cloned to a place where it can run every time the player spawns. The easiest way would be to place the LocalScript in the StarterPack or StarterGui, because LocalScripts run in the Backpack and PlayerGui.
Once you have a LocalScript running every time the player spawns, you'll have to create the areas to place the local parts. Below I have two examples of how to do this. The first places parts inside a Message in the character, and the second places them inside the Camera.
-- This script puts local parts inside a message which goes inside the character.
local Players = game:GetService("Players")
local player = Players.LocalPlayer -- create a reference for the current active player
local character = player.Character -- create a reference for the current character
-- At this point we're going to assume the script doesn't load before the character. In certain
-- cases, however, this can happen, and it's always good to be safe and to check for it.
local bin = Instance.new("Message") -- create the message object
bin.Parent = character
-- Now that the 'local part bin' is in the character, you can simply place any parts
-- you want inside of it. I'll write one for example purposes.
local platform = Instance.new("Part")
platform.CFrame = character.Torso.CFrame * CFrame.new(0, -3, 0)
platform.Anchored = true
platform.Size = Vector3.new(10, 1.2, 10)
platform.Parent = bin -- remember, parts go inside of 'bin', not workspace
-- This script puts local parts inside the camera.
local camera = workspace.CurrentCamera
-- 'camera' will be the containment model for all local parts. Below I copied the code from
-- before to create a local platform.
local platform = Instance.new("Part")
platform.CFrame = character.Torso.CFrame * CFrame.new(0, -3, 0)
platform.Anchored = true
platform.Size = Vector3.new(10, 1.2, 10)
platform.Parent = camera -- parts will now be placed in 'camera' instead of workspace.
When running these scripts, warnings may appear in the output window. These are the messages colored yellow, meaning they won't halt the LocalScript. ROBLOX Studio is just advising that you don't place parts in these locations. With the first, when the player's character is removed (from death, possibly) all the local parts will be removed. With the second LocalScript, even when the player dies, the local parts will remain on the client. This is due to the player's Camera not being removed when a character is killed.