ReplicatedStorage

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).

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

-- ReplicatedStorage > SharedModule

local SharedModule = {}

function SharedModule.greet(name)
    return "Hello, " .. name .. "!"
end

return SharedModule
-- ServerScriptService Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SharedModule = require(ReplicatedStorage:WaitForChild("SharedModule"))

print(SharedModule.greet("Server"))
-- StarterPlayerScripts LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SharedModule = require(ReplicatedStorage:WaitForChild("SharedModule"))


print(SharedModule.greet("Client"))

Remote Event in ReplicatedStorage

-- StarterPlayerScripts LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ExampleEvent = ReplicatedStorage:WaitForChild("ExampleEvent")

local function onEventFired(message)
    print(message)
end

ExampleEvent.OnClientEvent:Connect(onEventFired)
-- ServerScriptService Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ExampleEvent = ReplicatedStorage:WaitForChild("ExampleEvent")

local function fireEvent()
    ExampleEvent:FireAllClients("Hello from the server!")
end

fireEvent()
-- 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

-- 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)
-- 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)
Image 1
Image 2
Roblox Studio
  • 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.