Roblox Lua中的数据存储

问题描述 投票:-1回答:1

所以我目前正在尝试获取一个保存脚本,以与鼠标单击事件游戏一起使用。可以节省玩家的点击次数(点)。问题是,它似乎根本没有节省。页首横幅/鼠标单击事件有效,没有输出/脚本分析错误,并且该脚本位于ServerScriptService中。

这里是代码:

local DataStoreService = game:GetService("DataStoreService")
classData = DataStoreService:GetDataStore("PlayClass")
pointData = DataStoreService:GetDataStore("PlayPoints")

game.Players.PlayerAdded:Connect(function(player)
    local success, err = pcall(function()
        pointData:GetAsync("Player_"..player.UserId)
    end
    )
    if success then
        print("Loading Success!")
    end
    local success, err = pcall(function()
        classData:GetAsync("Player_"..player.UserId)
    end
    )
    if success then
        print("Loading Success!")
    end

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Points = Instance.new("IntValue", leaderstats)
    Points.Name = "Points"

    local Class = Instance.new("StringValue", leaderstats)
    Class.Name = "Class"
    Class.Value = "Wannabe"
    PlayerClass = player.leaderstats.Class
    PlayerPoints = player.leaderstats.Points
end)

workspace:WaitForChild("Sign")



workspace.Part.ClickDetector.MouseClick:Connect(function(player)
    workspace.Sign.Value.Value = workspace.Sign.Value.Value + 1
    workspace.Sign.SurfaceGui.SIGN.Text = workspace.Sign.Value.Value
    PlayerPoints.Value = workspace.Sign.Value.Value



    if PlayerPoints.Value < 49
    then
        PlayerClass.Value = "Wannabe"
    end

    if PlayerPoints.Value > 49
    then
        PlayerClass.Value = "Beginner"
    end

    if PlayerPoints.Value > 124
    then
        PlayerClass.Value = "Novice"
    end

    if PlayerPoints.Value > 249
    then
        PlayerClass.Value = "Intermediate"
    end

    if PlayerPoints.Value > 374
    then
        PlayerClass.Value = "Pro"
    end

    if PlayerPoints.Value > 499
    then
        PlayerClass.Value = "God"
    end

end
)

game.Players.PlayerRemoving:Connect(function(player)
    local success, err = pcall(function()
        pointData:SetAsync("Player_"..player.UserId, PlayerPoints.Value)
    end
    )
    if success then
        print ("Saving Success!")
    end
    local success, err = pcall(function()
        classData:SetAsync("Player_"..player.UserId, PlayerClass.Value)
    end
    )
    if success then
        print("Saving Success!")
    end
end)

它打印加载成功,但不打印保存成功。编辑:我尝试添加else语句以查看错误,但仍然无法打印任何内容。

lua roblox
1个回答
0
投票

我可以使用空白游戏,零件和脚本来复制您的问题。正如Kylaaa在他的评论中提到的,如果您这样做:

if success then
    print ("Saving Success!")
else
    print (err)
end 

...它将向您显示错误。从您的评论中我不确定您是否尝试过这种方式。另外,我没有在每次输出中都得到错误。就我而言,错误是:“ 403:如果未启用API访问,则无法从Studio写入DataStore。”启用它后,“保存成功”就很好了。

© www.soinside.com 2019 - 2024. All rights reserved.