Empty
Empty
Empty
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).
Empty
Empty
Empty
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
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"))
Événement Distant dans 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 dans 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
- 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é