Empty
Empty
Empty
ReplicatedStorage é um local onde você pode colocar objetos e scripts que precisam ser acessados tanto pelo servidor quanto pelos computadores dos jogadores (clientes).
Empty
Empty
Empty
Ajuda a compartilhar ativos comuns, como ferramentas, módulos e dados, entre o servidor e os jogadores, garantindo que todos tenham acesso aos mesmos recursos.
ModuleScript em 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"))
Evento Remoto em 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 em 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
- Elementos de GUI armazenados em ReplicatedStorage não são carregados na memória ou processados pelo cliente até serem necessários.
- Elementos de GUI em PlayerGui consomem memória, recursos de CPU, incluindo aqueles que estão invisíveis.
Se você achou este tutorial útil e gostaria de apoiar meu trabalho, por favor, considere me comprar um café.
Muito obrigado pelo seu apoio!
Me compre um café