로블록스 게임제작

유저 접속시 캐릭터 정보 가져오는 스크립트

Dean83 2024. 2. 13. 10:47

기본적으로 유저가 접속을 해야 모든 동작이 이루어 진다. 

유저가 접속했을 때 처리는 서버 스크립트에서도, 로컬 스크립트에서도 모두 가능하다. 

비동기로 wait 을 이용하여 접속이 완료될 때 까지 기다린 후 정보를 가져온다.

두개의 차이점은,

  • 로컬 스크립트 : "내 캐릭터" 를 알 수 있고 해당 기반으로 코딩
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

 

  • 서버 스크립트 : "접속한 전체 유저 캐릭터들" 을 알 수 있고 해당 기반으로 코딩
game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	
	print(player.LocaleId)
	print(player.UserId)
	print(player.Name)
end)