我正在制作一个roblox游戏,我需要它来保存数据,但它不会



它不会给出错误消息,但它不会保存我启用了API服务不知道为什么它不起作用,请帮忙!

"本地dataStoreService=game:GetService("dataStoreService"(localgameStore=dataStoreService:GetDataStore("TestDataStore"(

game.Players.PlayerAdded:Connect(function(plr)
local leaderstat = Instance.new("Folder" , plr)`enter code here`
leaderstat.Name = "leaderstats"
local Currency = Instance.new("IntValue" , leaderstat)
Currency.Name = "Currency"
Currency.Value = 1
local CurrencyData
local success, errorMsg = pcall(function()
CurrencyData = gameStore:GetAsync(plr.UserId .. "-Currency")
end)
if success == true then
Currency.Value = CurrencyData
else
print("Cant recover data because " .. errorMsg)
end
end)
--Save data when server shut down
game:BindToClose(function()
for i , plr in pairs(game.Players:GetChildren()) do
local success , errorMsg = pcall(function()
gameStore:SetAsync(plr.UserId .. "-level" , plr.leaderstats.Currency.Value)
end)
if success then
print("Data Secured")
else
print("Error while saving data because " .. errorMsg)
end
end
end)
--Save data when somebody leaves
game.Players.PlayerRemoving:Connect(function(plr)
for i , plr in pairs(game.Players:GetChildren()) do
local success , errorMsg = pcall(function()
gameStore:SetAsync(plr.UserId .. "-level" , plr.leaderstats.Currency.Value)
end)
if success then
print("Data Secured")
else
print("Error while saving data because " .. errorMsg)
end
end

end(''

我认为你必须这样写加载脚本(我已经有一段时间没有存储数据了,所以可能不是这样(:

local success, errorMsg = pcall(function()
CurrencyData = gameStore:GetAsync(plr.UserId.Currency)
end)

最新更新