有没有办法用我的排行榜解决这个错误?
Posted
技术标签:
【中文标题】有没有办法用我的排行榜解决这个错误?【英文标题】:Is there anyway to fix this Error with my Leaderboard? 【发布时间】:2021-05-07 07:03:54 【问题描述】:我的排行榜尝试更新时出现此错误。 502:API 服务拒绝请求并出现错误。数据存储类型 Sorted 的值格式无效。 参数名称:值 这是脚本:
local CoinsDS = game:GetService("DataStoreService"):GetOrderedDataStore("MoneyLeaderboard")
local suffixes = '','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'
local function format(val)
for i=1, #suffixes do
if tonumber(val) < 10^(i*3) then
return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
end
end
end
while true do
for _,Player in pairs(game.Players:GetPlayers()) do
local Leaderstats = Player:FindFirstChild("leaderstats")
if Leaderstats then
local coins = Leaderstats:FindFirstChild("CloudCoins")
if coins then
CoinsDS:SetAsync(Player.UserId, coins.Value)
end
end
end
local boards = workspace:WaitForChild("LeaderboardStuff")
local sellected = boards:WaitForChild("ViewCoins")
local Count = boards:WaitForChild("CountCoins")
local Info = Count:WaitForChild("Info")
for i,v in pairs(sellected:WaitForChild("GUI"):GetChildren()) do
v:Destroy()
end
for _,v in pairs(boards:WaitForChild("TopCoins"):GetChildren()) do
v:Destroy()
end
local Success, Err = pcall(function()
local Data = CoinsDS:GetSortedAsync(false, 10)
local LPage = Data:GetCurrentPage()
for i, v in pairs(LPage) do
if v.key ~= nil and tonumber(v.key) and tonumber(v.key) > 0 then
local name = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
if name ~= nil then
local Val = v.value
local NewObj = game.ServerStorage:WaitForChild("TemplateCoins"):Clone()
NewObj:WaitForChild("Player").Text = name
NewObj:WaitForChild("Coins").Text = format(Val)
NewObj:WaitForChild("Stats").Text = i.."°"
NewObj:WaitForChild("PlayerIcon").Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..(v.key).."&width=150&height=150&format=png"
local boards = workspace:WaitForChild("LeaderboardStuff")
local sellected = boards:WaitForChild("ViewCoins")
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.09 * #sellected:WaitForChild("GUI"):GetChildren()), 0)
NewObj.Parent = sellected:WaitForChild("GUI")
end
end
end
end)
if not Success then
error(Err)
end
for i=30,1,-1 do
wait(1)
Info:WaitForChild("UpdateTime").Text = "Update In("..i..")"
end
wait()
end
该值是一个数字值。它的值是 44909800000000002968496892153981593868198948444510090605799389908923580416 或 44.9TVg。
【问题讨论】:
我相信您的技能足以从您的代码中删除与问题无关的任何内容,如minimal reproducible example。这是完整的错误信息吗?根据手动错误502应该提供另一个错误号 【参考方案1】:我对此并不擅长,我可能错了,但是,我相信您需要将 UserId 转换为字符串,所有 DataStore 键都必须是字符串,UserId 返回一个 int。
【讨论】:
【参考方案2】:对不起,我只是检查了这个,但我找到了解决方案。基本上我将数字压缩并保存到排行榜数据存储中:
local Coins = coins ~= 0 and math.floor(math.log(coins) / math.log(1.00000000000001)) or 0
然后,当我循环遍历 DataStore 时,我会将其解包到其原始编号:
Val = Val ~= 0 and (1.00000000000001^Val) or 0
【讨论】:
以上是关于有没有办法用我的排行榜解决这个错误?的主要内容,如果未能解决你的问题,请参考以下文章