What does a local script do that a regular script can’t do?
What does a script do that a local script can’t do?
A local script is a script that’d only run for the client. [Notice, a few exceptional actions could replicate from it to server, such as animations.]
A server script is a script which runs its code for the entire server.
A basic example:
--local script
local work = game:GetService("Workspace")
local Base = work:WaitForChild("MyPart")
while true do
local newPart = Base:Clone()
newPart.Parent = work
task.wait(1)
end
In this case, only YOU - the client, would be able to see the changes for himself.
--Server
local work = game:GetService("Workspace")
local Base = work:WaitForChild("MyPart")
while true do
local newPart = Base:Clone()
newPart.Parent = work
task.wait(1)
end
However, in this case, since it is inside a server script, it’d replicate and show to everyone in the server.
More info here: What is the difference between a script and a local script?
It is also important to notice:
1.In a local script, you can access the local script easily by doing:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
While in a normal script, you’d have to get the player through any event or function [related to an event such as PlayerAdded
].
2.Local scripts are easier to be bypassed and get deleted by exploiters.