Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can Someone Please Explain The difference between a Script and a Local Script?

Im not sure if it would be easier to do local scripts or regular scripts, or the funcitonality of a local script. Thanks In Advance!!

1 answer

✓ Accepted answer

Scripts

Normal scripts are scripts that perform actions on the server. Things such as accessing the player for receiving input or GUI actions should not be done in Scripts.

Scripts are great for doing something like dealing damage to a Humanoid. This is because the damage is replicated to the server instead of the client that contains that Humanoid. Here's an example:

script.Parent.Touched:Connect(function(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
    if player then
	    player.Character.Humanoid.Health = 0
    end
end)

Scripts are also necessary for doing things like receiving and sending HTTP information via the HttpService. One client can't possibly do this.

Another thing to keep in mind is that normal scripts can access ServerStorage while the client can't. (It's in the name.)

LocalScripts

LocalScripts are scripts that perform actions on the client. Things such as receiving input and GUI actions should be done in LocalScripts as opposed to normal Scripts. There is one thing LocalScripts can do that Scripts can't, and that is to receive the player from the client: the LocalPlayer. The LocalPlayer applies to the player on the client and this allows the script to replicate to all players in the game simply by using LocalPlayer. Here's an example of that:

local player = game.Players.LocalPlayer
player.PlayerGui.ScreenGui.TextLabel.Text = "Hello"

The Text property replicates to the LocalPlayer, which can, in turn, replicate to all of the players so that the text shows up on every player.

When using LocalScripts, keep in mind that they cannot access ServerStorage or ServerScriptService because those services are server-side only (normal scripts can access them). They can access ReplicatedStorage, which is visible to both the server and client.

This discussion is preserved as it was. New answers, comments, and votes are closed.