【发布时间】:2020-08-08 03:29:57
【问题描述】:
所以我正在尝试制作游戏,但无法保留统计数据。我已经有一个有效的死亡计数器,但不知道如何保存它,每次我重新加入时它都会重置。这是我尝试过的两个代码:
1)
local pointsDataStore = game:GetService("DataStoreService"):GetDataStore("Deaths")
game.Players.PlayerAdded:Connect(function(player)
local playerKey = "Player_" .. player.UserId
local success, err = pcall(function()
pointsDataStore:UpdateAsync(playerKey, function(oldValue)
local newValue = oldValue or 0
newValue = newValue + 0
return newValue
end)
end)
end)
2)
local DS = game:GetService("DataStoreService"):GetDataStore("Points")
game.Player.PlayerAdded:connect(plr)
local leaderstats = Instance.new("Model",plr)
leaderstats.Name = "leaderstats"
local currency = Instance.new("IntValue", leaderstats)
currency.Name = "Deaths"
currency.Value = 1
while wait(5) do
DS:SetAsync(plr.userId.."_DS", currency.Value)
end
end)
【问题讨论】:
标签: roblox