我制作了这个简单的数据存储脚本,该脚本应该加载数据存储并将值添加到您的 Leaderstats 中。它在第 29 行失败,该行已在脚本中标记。我究竟做错了什么?
local dts = game:GetService("DataStoreService")
local money = dts:GetDataStore("Currency-0")
--Currency is set up like this:
--{CASH, GEMS}
--It is a table storing both values.
game.Players.PlayerAdded:Connect(function(plr)
local model = Instance.new("Model") -- lets set up our leaderstats!
model.Name = "leaderstats"
model.Parent = plr
local moneyValue = Instance.new("IntValue")
moneyValue.Name = "Cash"
local gemValue = Instance.new("IntValue")
gemValue.Name = "Gems"
local key = "USER_" .. plr.Name .. "_" .. plr.UserId -- advanced player key
local storedCash -- setting up a variable
local success, err = pcall(function()
storedCash = money:GetAsync(key)
end)
if success then
moneyValue.Value = storedCash[1] -- this is the line that messes up
gemValue.Value = storedCash[2]
-- we've set that, now we must make it show
moneyValue.Parent = model
else
moneyValue.Value = 0
gemValue.Value = 0
money:SetAsync(key, {0, 0})
end
end)
我的错误::29:尝试索引本地“storedCash”(零值)
我制作了一个简单的数据存储脚本,它应该将值添加到 Leaderstats 中。但是第29行显示错误,我做错了什么?