클라이언트 스크립트

LocalScript (클라이언트 스크립트)

LocalScript는 플레이어의 컴퓨터 (클라이언트)에서만 실행되는 코드입니다.

이 스크립트는 로컬 플레이어와 관련된 UI 상호작용, 카메라 제어, 모든 플레이어가 볼 필요가 없는 효과 등을 처리합니다.

사용자 인터페이스 (UI) 상호작용GUI 요소 업데이트 또는 상호작용
플레이어 입력키보드, 마우스 또는 게임패드 이벤트와 같은 플레이어 입력 처리.
로컬 효과로컬 플레이어에게만 보이는 시각적 또는 오디오 효과
로컬 데이터 처리로컬 설정 또는 선호도, 인벤토리 관리
반응성클라이언트에서 실행되므로 플레이어의 행동에 훨씬 더 빠르게 반응합니다. 입력 감지 시 서버와의 통신이 필요하지 않아 지연이 최소화됩니다.
효율성로컬에서 이벤트를 처리하여 서버의 부하를 줄이며, 특히 많은 플레이어가 있는 게임에서 중요합니다.
-- 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)
-- 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)

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

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

커피 한 잔 사주기