최고점수라던가,
이미 구매한 아이템 처럼, 사용자가 종료를 해도 데이터를 저장해야할 때가 있어요.
이때 Data Store 라는 것을 사용하는데
플레이어의 값을 저장하고, 다시 게임 할 때 불러오는 예제입니다.
local dataStoreService = game:GetService("DataStoreService")
local playerDataStore = dataStoreService:GetDataStore("PlayerDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local score = Instance.new("IntValue")
score.Name = "Score"
score.Parent = leaderstats
local l_score
local success,errMsg = pcall (function()
l_score = playerDataStore:GetAsync(player.UserId.."-Score")
end)
if success then
score.Value = l_score
else
warn ("Failed to read score:"..errMsg)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errMsg = pcall (function() playerDataStore:SetAsync(player.UserId.."-Score", player.leaderstats.Score.Value) end)
if success then
print ("Success to save score")
else
warn ("Failed to save score:"..errMsg)
end
end)
'Roblox Script' 카테고리의 다른 글
#10 : 플레이어 머리에 이름 표시 - Player Title (Team / Role) BillboardGui (0) | 2020.08.06 |
---|---|
#9 : RemoteEvent로 Sever에서 local function 호출 (0) | 2020.08.06 |
#7 : Remote Event로 클라이언트에서 서버 호출하기 (0) | 2020.08.02 |
#6 - 효과음 넣기 (Sound effect) (0) | 2020.08.02 |
#4 : 블록 만지면 점수 올리기 (0) | 2020.08.02 |