ReplicatedStorage

ReplicatedStorage est un emplacement où vous pouvez stocker des objets et des scripts qui doivent être accessibles à la fois par le serveur et les ordinateurs des joueurs (clients).

Il permet de partager des ressources communes, comme des outils, des modules et des données, entre le serveur et les joueurs, garantissant que tout le monde a accès aux mêmes ressources.

ModuleScript dans 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"))

Événement Distant dans 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 dans 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
  • Les éléments d'interface utilisateur stockés dans ReplicatedStorage ne sont pas chargés en mémoire ou traités par le client tant qu'ils ne sont pas nécessaires.
  • Les éléments d'interface utilisateur dans PlayerGui consomment de la mémoire et des ressources CPU, y compris ceux qui sont invisibles.

Si ce tutoriel vous a été utile et que vous souhaitez soutenir mon travail, veuillez envisager de m'offrir un café.

Merci beaucoup pour votre soutien !

M'offrir un café