(使用roblox studio)
大家好,我可能不会涵盖你们解决这个问题所需的一切,因为我从未发过论坛帖子。我的问题是我的数据存储。我已经在一个游戏上工作了大约一个月,我虽然添加货币系统会很好,但是对于货币系统,我意识到我需要一种方法来保存玩家购买的货币和物品。所以,我读了数据存储,表格所有的东西。过了一会儿,我出来了一个功能正常的数据库。它在工作室中没有任何缺陷(显然启用了API ### vices)。但是当我从网站上玩游戏时似乎没有注册。这是我正在使用的脚本
local HttpService = game:GetService("HttpService")
local DataStore = game:GetService("DataStoreService")
local data1 = DataStore:GetDataStore("PawsDataStore")
local data2 = DataStore:GetDataStore("PawsDataStore2")
local playerdata = {}
local OwnedChampions = {}
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local rank = Instance.new("IntValue", leaderstats)
rank.Name = "Rank"
local shards = Instance.new("IntValue", leaderstats)
shards.Name = "Shards"
local champions = Instance.new("Folder", player)
champions.Name = "OwnedChampions"
local abyssal = Instance.new("BoolValue", champions)
abyssal.Name = "Abyssal"
local biomage = Instance.new("BoolValue", champions)
biomage.Name = "Biomage"
local permafrost = Instance.new("BoolValue", champions)
permafrost.Name = "Permafrost"
local holder = Instance.new("BoolValue", champions)
holder.Name = " "
if not data1:GetAsync(player.UserId, playerdata) then
print("Making new data entry for ".. player.Name)
playerdata[1] = 1
playerdata[2] = 500
OwnedChampions[1] = false
OwnedChampions[2] = false
OwnedChampions[3] = false
local encoding = HttpService:JSONEncode(playerdata)
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data1:SetAsync(player.UserId, encoding)
data2:SetAsync(player.UserId, encoding2)
player.leaderstats.Rank.Value = playerdata[1]
player.leaderstats.Shards.Value = playerdata[2]
player.OwnedChampions.Abyssal.Value = OwnedChampions[1]
player.OwnedChampions.Biomage.Value = OwnedChampions[2]
player.OwnedChampions.Permafrost.Value = OwnedChampions[3]
player.leaderstats.Rank.Changed:connect(function()
playerdata[1] = player.leaderstats.Rank.Value
local encoding = HttpService:JSONEncode(playerdata)
data1:SetAsync(player.UserId, encoding)
end)
player.leaderstats.Shards.Changed:connect(function()
playerdata[2] = player.leaderstats.Shards.Value
local encoding = HttpService:JSONEncode(playerdata)
data1:SetAsync(player.UserId, encoding)
end)
player.OwnedChampions.Abyssal.Changed:connect(function()
OwnedChampions[1] = player.OwnedChampions.Abyssal.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
player.OwnedChampions.Biomage.Changed:connect(function()
OwnedChampions[2] = player.OwnedChampions.Biomage.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
player.OwnedChampions.Permafrost.Changed:connect(function()
OwnedChampions[3] = player.OwnedChampions.Permafrost.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
else
local encodedvalues = data1:GetAsync(player.UserId)
local decoding = HttpService:JSONDecode(encodedvalues)
playerdata = decoding
rank.Value = decoding[1]
shards.Value = decoding[2]
local encodedvalues2 = data2:GetAsync(player.UserId)
local decoding2 = HttpService:JSONDecode(encodedvalues2)
OwnedChampions = decoding2
abyssal.Value = decoding2[1]
biomage.Value = decoding2[2]
permafrost.Value = decoding2[3]
player.leaderstats.Rank.Changed:connect(function()
playerdata[1] = player.leaderstats.Rank.Value
local encoding = HttpService:JSONEncode(playerdata)
data1:SetAsync(player.UserId, encoding)
end)
player.leaderstats.Shards.Changed:connect(function()
playerdata[2] = player.leaderstats.Shards.Value
local encoding = HttpService:JSONEncode(playerdata)
data1:SetAsync(player.UserId, encoding)
end)
player.OwnedChampions.Abyssal.Changed:connect(function()
OwnedChampions[1] = player.OwnedChampions.Abyssal.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
player.OwnedChampions.Biomage.Changed:connect(function()
OwnedChampions[2] = player.OwnedChampions.Biomage.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
player.OwnedChampions.Permafrost.Changed:connect(function()
OwnedChampions[3] = player.OwnedChampions.Permafrost.Value
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data2:SetAsync(player.UserId, encoding2)
end)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local encoding = HttpService:JSONEncode(playerdata)
local encoding2 = HttpService:JSONEncode(OwnedChampions)
data1:SetAsync(player.UserId, encoding)
data2:SetAsync(player.UserId, encoding2)
end)
这是一个放在服务器脚本服务中的普通脚本。我也认为这可能有助于我注意到当我在网站上开始游戏时,它可以很好地加载数据,但似乎无法写入数据存储。我在工作室创建的数据会保存到数据存储区并正常运行。提前谢谢!
pawches