Empty
Empty
Empty
ReplicatedStorage è un luogo dove puoi mettere oggetti e script che devono essere accessibili sia dal server che dai computer dei giocatori (client).
Empty
Empty
Empty
Aiuta a condividere risorse comuni, come strumenti, moduli e dati, tra il server e i giocatori, garantendo che tutti abbiano accesso alle stesse risorse.
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
- Gli elementi GUI memorizzati in ReplicatedStorage non vengono caricati in memoria o elaborati dal client fino a quando non sono necessari.
- Gli elementi GUI in PlayerGui consumano memoria e risorse della CPU, comprese quelle che sono invisibili.
Se hai trovato utile questo tutorial e desideri supportare il mio lavoro, considera di offrirmi un caffè.
Grazie mille per il tuo supporto!
Offrimi un caffè