본문 바로가기

Roblox Script

#9 : RemoteEvent로 Sever에서 local function 호출

플레이어가 들어왔을때 플레이어 화면에 환영 메세지를 띄워줍니다.
즉, RemoteEvent를 통해, 서버에서 localscript의 함수를 event로 호출합니다.
(다른 플레이어에게는 환영 메시지가 안보입니다.)

-- ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventJoin = ReplicatedStorage:WaitForChild("RemoteEventNotify")

local function playerJoin(player) 
     wait(5)
    remoteEventJoin:FireClient(player, "Welcome to Nobakee Game!!!")
end

game.Players.PlayerAdded:Connect(playerJoin)

-- localScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventNoti = ReplicatedStorage:WaitForChild("RemoteEventNotify")

local function onNotifyPlayer(noti_msg)  
     local player_gui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui') 
     local screen_gui = player_gui:WaitForChild("ScreenGui")
     screen_gui.WelcomeBox.Text = noti_msg
     wait(5)
     screen_gui.WelcomeBox.Text = ""
end

remoteEventNoti.onClientEvent:Connect(onNotifyPlayer)