roblox:DataStore 不加载数据

我创建了一个数据存储库但是它没有加载保存的值。 我尝试在实际服务器上,但仍然没有反应。 而且它只输出日志,没有错误,没有警告。

    local DataStoreService = game:GetService("DataStoreService")
    local DataStore = DataStoreService:GetDataStore("SkinStats")
    game.Players.PlayerAdded:Connect(function(Player)
        local Leaderstats = Instance.new("Folder", Player)
        Leaderstats.Name = "leaderstats"
        local Cash= Instance.new("IntValue", Leaderstats)
        Cash.Name = "Cash"
        Cash.Value = 100
        local Kills= Instance.new("IntValue", Leaderstats)
        Kills.Name = "Kills"
        Kills.Value = 0

        local Data = DataStore:GetAsync(Player.UserId)
        print(Data)
        if Data then
            Cash.Value = Data["Cash"]
            Kills.Value = Data["Kills"]
            print("也可以工作")
        end
    end)

    game.Players.PlayerRemoving:Connect(function(Player)
        DataStore:SetAsync(Player.UserId, {
            ["Cash"] = Player.leaderstats.Cash.Value;
            ["Kills"] = Player.leaderstats.Kills.Value;
        })
    end)

原文链接 https://stackoverflow.com/questions/70810738

点赞
stackoverflow用户12839543
stackoverflow用户12839543

你保存数据的方式有问题。你需要添加逗号,而不是分号;


    game.Players.PlayerRemoving:Connect(function(Player)
        DataStore:SetAsync(Player.UserId, {
            ["Cash"] = Player.leaderstats.Cash.Value,
            ["Kills"] = Player.leaderstats.Kills.Value
        })
    end)
2022-01-24 17:03:42