所以我在Roblox做一个小动物。我有一个数据存储区,用于保存排行榜的价值,即硬币和检查点。我拥有的数据存储在ServerScriptService中。
问题是,当玩家第一次加入游戏时,例如,他们完成了游戏的前5个级别,并获得了2个硬币。下次他们加入游戏时,他们仍然处于5级,并且他们还有上一游戏的2个硬币。但是如果他们现在玩游戏(即他们第二次登录游戏)并且假设他们达到了10级并拥有4个硬币,则该过程应该类似于如果玩家现在离开游戏,并且当他们重新加入时,他们应该在10级,并且应该有4个硬币。
但是发生的情况是,他们不在10级并且没有4个硬币,他们仍然在5级并且他们的硬币为2。就像他们的进步是第一次比赛一样。
为什么此数据存储区不第三次在玩家登录游戏时更新排行榜上的值?依此类推?
这里是保存整个数据存储的脚本,该脚本位于ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Checkpoint = Instance.new("IntValue", leaderstats)
Checkpoint.Name = "Checkpoint"
Checkpoint.Value = 1
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0
--Checkpoint Section
player.CharacterAdded:Connect(function(character)
repeat wait() until player.character ~= nil
local checkpoint = game.Workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position +
Vector3.new(0, 2, 0))
end)
-- Data Store Section
local playerUserId = "Player_"..player.UserId
print(playerUserId)
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
if data then
coins.Value = data.Coins
Checkpoint.Value = data.Checkpoint
-- Set our data equal to the current Coins
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
Coins = player.leaderstats.Coins.Value;
Checkpoint = player.leaderstats.Checkpoint.Value;
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error saving the data!")
warn(errormessage)
end
end)
请帮忙,因为我确实需要答案。
谢谢
这也发生在我身上,我认为您正在Roblox Studio中测试游戏。在Studio中,有时会出现错误。尝试发布游戏,然后检查它是否可以运行。