Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

OrderedData surfacegui isn't working?

Asked by
Relatch 550 Moderation Voter
8 years ago

I have a OrderedData surfacegui, and when displaying the names of the player, it removes the first number from their id. For example, say it's displaying me; it would say "CLONE752", because it removes the first number from my id. I'm not sure why it's doing that, and help is appreciated.

local service = game:GetService("HttpService")
local data = game:GetService("DataStoreService")
local orderedData = data:GetOrderedDataStore("wins")

while wait(60) do
    local place = 0
    for _, info in pairs(orderedData:GetSortedAsync(false, 5):GetCurrentPage()) do
        local plrID = info.key:sub(7)
        local data = tostring(info.value)
        print(plrID)
        place = place + 1
        local line = script.Parent:WaitForChild("Frame"):WaitForChild("Line" .. tostring(place))
        line.Text = "#" .. tostring(place) .. " | " .. service:GetAsync("http://roproxy.pw/rapi/GetUsernameById/" .. plrID, true) .. " | " .. data
    end
end

This is the script that saves the data:

local data = game:GetService("DataStoreService")
local winsData = data:GetOrderedDataStore("wins")
local pointsData = data:GetOrderedDataStore("points")

function UpdateDataStore(player)
    if player:FindFirstChild("leaderstats") then
        local stats = player.leaderstats
        local currentWins = stats:WaitForChild("Wins")
        local currentPoints = stats:WaitForChild("Points")

        local result = pcall(function()
            winsData:SetAsync("users_" .. tonumber(player.userId), currentWins.Value)
            pointsData:SetAsync("users_" .. tonumber(player.userId), currentPoints.Value)
        end)

        if not result then
            wait(60) 
            UpdateDataStore(player)
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

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

    local wins = Instance.new("IntValue", stats)
    wins.Name = "Wins"

    local Key = "users_" .. tonumber(player.userId)

    pointsData:SetAsync(Key, (pointsData:GetAsync(Key) or 0))
    winsData:SetAsync(Key, (winsData:GetAsync(Key) or 0))

    points.Value = pointsData:GetAsync(Key)
    wins.Value = winsData:GetAsync(Key)
end)

1 answer

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
8 years ago

Although the code looks perfectly fine that it should work, I wasn't able to test the api. But there is a method of getting the username from userid by something other than getasync.

function UsernameFromID(ID)
    if type(ID) ~= "number" then
        return
    end
    local sets = game:service("InsertService"):GetUserSets(ID)
    for k, v in next, sets do
        if v.Name == "My Models" then
            return v.CreatorName
        end
    end
end
print(UsernameFromID(31554827))

This will work on any situation. Even if the game was tested from Roblox Studio.

So far, this is what I was able to convert it into. Try running the game again, what does it print? It should print something like "users_31554827---31554827"

local service = game:GetService("HttpService")
local data = game:GetService("DataStoreService")
local orderedData = data:GetOrderedDataStore("wins")
function UsernameFromID(ID)
    if type(ID) ~= "number" then
        return
    end
    local sets = game:service("InsertService"):GetUserSets(ID)
    for k, v in next, sets do
        if v.Name == "My Models" then
            return v.CreatorName
        end
    end
end
while wait(60) do
    for i, info in ipairs(orderedData:GetSortedAsync(false,5):GetCurrentPage()) do
        local plrID = info.key:sub(7)
        local data = tostring(info.value)
        print(info.key.."---"..plrID)
        local line = script.Parent:WaitForChild("Frame"):WaitForChild("Line" .. tostring(place))
        line.Text = "#" ..i.. " | " .. UsernameFromID(plrID) .. " | " .. data
    end
end

If it prints something like "users31554827---31554827" Then you would know that for some reason, the DataStore didn't save data right last time, or that underscores aren't allowed anymore on DataStore?

0
It printed "31554827 --- 1554827" Relatch 550 — 8y
Ad

Answer this question