LocalScript (클라이언트 스크립트)
Empty
Empty
Empty
LocalScript는 플레이어의 컴퓨터 (클라이언트)에서만 실행되는 코드입니다.
Empty
Empty
Empty
이 스크립트는 로컬 플레이어와 관련된 UI 상호작용, 카메라 제어, 모든 플레이어가 볼 필요가 없는 효과 등을 처리합니다.
Empty
Empty
Empty
사용자 인터페이스 (UI) 상호작용 | GUI 요소 업데이트 또는 상호작용 |
플레이어 입력 | 키보드, 마우스 또는 게임패드 이벤트와 같은 플레이어 입력 처리. |
로컬 효과 | 로컬 플레이어에게만 보이는 시각적 또는 오디오 효과 |
로컬 데이터 처리 | 로컬 설정 또는 선호도, 인벤토리 관리 |
Empty
Empty
Empty
반응성 | 클라이언트에서 실행되므로 플레이어의 행동에 훨씬 더 빠르게 반응합니다. 입력 감지 시 서버와의 통신이 필요하지 않아 지연이 최소화됩니다. |
효율성 | 로컬에서 이벤트를 처리하여 서버의 부하를 줄이며, 특히 많은 플레이어가 있는 게임에서 중요합니다. |
Empty
Empty
Empty
-- LocalScript in StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local givePointsEvent = ReplicatedStorage:WaitForChild("GivePointsEvent")
local function triggerGivePoints(points)
givePointsEvent:FireServer(points)
end
-- Example usage: Trigger the event when the player clicks a GUI button
local screenGui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))
local button = Instance.new("TextButton", screenGui)
button.Size = UDim2.new(0, 200, 0, 50)
button.Position = UDim2.new(0.5, -100, 0.5, -25)
button.Text = "Get Points"
button.MouseButton1Click:Connect(function()
triggerGivePoints(10)
end)
Empty
Empty
Empty
-- Script in ServerScriptService
-- Get the RemoteEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local givePointsEvent = ReplicatedStorage:WaitForChild("GivePointsEvent")
-- Function to handle the remote event
local function onGivePoints(player, points)
-- Add points to the player's leaderstats
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local score = leaderstats:FindFirstChild("Points")
if score then
score.Value = score.Value + points
print(player.Name .. " received " .. points .. " points!")
end
end
end
-- Connect the function to the OnServerEvent of the remote event
givePointsEvent.OnServerEvent:Connect(onGivePoints)