Script Types & Locations
Roblox uses three core script containers:
- Script β server-side gameplay and secure logic (place in ServerScriptService).
- LocalScript β client-side UI, input, camera (place under player containers like StarterPlayerScripts, PlayerGui, StarterPack, or ReplicatedFirst).
- ModuleScript β reusable code libraries, required by Scripts or LocalScripts.
Examples
-- Server Script (ServerScriptService)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr) print("Welcome", plr.Name) end)
-- LocalScript (StarterPlayer βΈ StarterPlayerScripts)
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input,gp) if not gp and input.KeyCode==Enum.KeyCode.F then print("F pressed") end end)
-- ModuleScript
local M = {}; function M.add(a,b) return a+b end; return M
Why location matters: LocalScripts only run in specific client containers (PlayerGui, StarterPlayerScripts, Backpack/Tool, Character, ReplicatedFirst). Server scripts donβt run on the client and can access server-only services.