Empty
Empty
Empty
ReplicatedStorage is a place where you can put objects and scripts that need to be accessed by both the server and the players' computers (clients).
Empty
Empty
Empty
It helps share common assets, like tools, modules, and data, between the server and players, ensuring everyone has access to the same resources.
ModuleScript in ReplicatedStorage
Empty
Empty
Empty
-- ReplicatedStorage > SharedModule
local SharedModule = {}
function SharedModule.greet(name)
return "Hello, " .. name .. "!"
end
return SharedModule
Empty
Empty
Empty
-- ServerScriptService Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SharedModule = require(ReplicatedStorage:WaitForChild("SharedModule"))
print(SharedModule.greet("Server"))
Empty
Empty
Empty
-- StarterPlayerScripts LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SharedModule = require(ReplicatedStorage:WaitForChild("SharedModule"))
print(SharedModule.greet("Client"))
Remote Event in ReplicatedStorage
Empty
Empty
Empty
-- StarterPlayerScripts LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ExampleEvent = ReplicatedStorage:WaitForChild("ExampleEvent")
local function onEventFired(message)
print(message)
end
ExampleEvent.OnClientEvent:Connect(onEventFired)
Empty
Empty
Empty
-- ServerScriptService Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ExampleEvent = ReplicatedStorage:WaitForChild("ExampleEvent")
local function fireEvent()
ExampleEvent:FireAllClients("Hello from the server!")
end
fireEvent()
Empty
Empty
Empty
-- ServerScriptService Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ExampleEvent = ReplicatedStorage:WaitForChild("ExampleEvent")
local function fireEvent(player)
ExampleEvent:FireClient(player, "Hello from the server!")
end
game.Players.PlayerAdded:Connect(function(player)
fireEvent(player)
end)
ScreenGui in ReplicatedStorage
Empty
Empty
Empty
-- StarterPlayerScripts LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local ShowWelcomeGuiEvent = ReplicatedStorage:WaitForChild("ShowWelcomeGuiEvent")
local function displayGui(playerName)
local guiTemplate = ReplicatedStorage:WaitForChild("WelcomeGuiTemplate")
local guiClone = guiTemplate:Clone()
local textLabel = guiClone:FindFirstChild("TextLabel")
if textLabel then
textLabel.Text = "Welcome, " .. playerName
end
guiClone.Parent = playerGui
end
-- Connect the function to the RemoteEvent
ShowWelcomeGuiEvent.OnClientEvent:Connect(displayGui)
Empty
Empty
Empty
-- StarterPlayerScripts LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local ShowWelcomeGuiEvent = ReplicatedStorage:WaitForChild("ShowWelcomeGuiEvent")
local function displayGui(playerName)
local guiTemplate = ReplicatedStorage:WaitForChild("WelcomeGuiTemplate")
local guiClone = guiTemplate:Clone()
local textLabel = guiClone:FindFirstChild("TextLabel")
if textLabel then
textLabel.Text = "Welcome, " .. playerName
end
guiClone.Parent = playerGui
end
-- Connect the function to the RemoteEvent
ShowWelcomeGuiEvent.OnClientEvent:Connect(displayGui)
Roblox Studio
Empty
Empty
Empty
- GUI elements stored in ReplicatedStorage are not loaded into memory or processed by the client until they are needed.
- GUI elements in PlayerGui consume memory, CPU resources, including those that are invisible.