ReplicatedStorage

ReplicatedStorage ist ein Bereich, in dem Sie Objekte und Skripte ablegen können, die sowohl vom Server als auch von den Computern der Spieler (Clients) zugegriffen werden müssen.

Es hilft dabei, gemeinsame Ressourcen wie Werkzeuge, Module und Daten zwischen dem Server und den Spielern zu teilen und sicherzustellen, dass alle auf dieselben Ressourcen zugreifen können.

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-Elemente, die in ReplicatedStorage gespeichert sind, werden erst bei Bedarf in den Speicher geladen oder vom Client verarbeitet.
  • GUI-Elemente in PlayerGui verbrauchen Speicher- und CPU-Ressourcen, auch wenn sie unsichtbar sind.

Wenn Sie dieses Tutorial hilfreich fanden und meine Arbeit unterstützen möchten, können Sie mir gerne einen Kaffee spendieren.

Vielen Dank für Ihre Unterstützung!

Kaufen Sie mir einen Kaffee