【发布时间】:2016-09-10 19:30:32
【问题描述】:
这些不起作用有什么原因吗?
玩家加入脚本:
local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local points = Instance.new("IntValue", stats)
points.Name = "Points"
local credits = Instance.new("IntValue", stats)
credits.Name = "Credits"
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save format: (points, credits)
points.Value = savedValues[1]
credits.Value = savedValues[2]
else
local ValuesToSave = {points.Value, credits.Value}
DataStore:SetAsync(key, ValuesToSave)
end
end)
还有这个玩家离开时的其他脚本。
local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
--Save key: {points, credits}
local valuesToSave = {player.leaderstats.Points.Values, player.leaderstats.Credits.Values}
DataStore:SetAsync(key, valuesToSave)
end)
这是我正在开发的一款游戏,请证明(RLua 是 Roblox Lua,如果你不知道的话)。
【问题讨论】:
-
您能分享一下您希望代码做什么以及它会做什么吗?
-
试图澄清。修正语法