ReplicatedStorage (복제 스토리지)

ReplicatedStorage는 서버와 플레이어의 컴퓨터(클라이언트)가 접근해야 하는 객체와 스크립트를 보관하는 장소입니다.

서버와 플레이어 사이에서 공통 자산(예: 도구, 모듈, 데이터)을 공유하여 모든 사용자가 동일한 자원에 접근할 수 있도록 돕습니다.

ReplicatedStorage 내의 ModuleScript

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

ReplicatedStorage 내의 Remote Event

-- 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)

ReplicatedStorage 내의 ScreenGui

-- 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
  • ReplicatedStorage에 저장된 GUI 요소는 필요할 때까지 메모리에 로드되거나 클라이언트에 의해 처리되지 않습니다.
  • PlayerGui의 GUI 요소는 보이지 않는 경우에도 메모리와 CPU 자원을 소모합니다.

이 튜토리얼이 도움이 되셨다면, 저의 작업을 지원하기 위해 커피 한 잔을 사주시면 감사하겠습니다.

지원해 주셔서 정말 감사합니다!

커피 한 잔 사주기