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

LeaderboardHandler:22: attempt to index string with 'Text'?

Asked by 4 years ago

Uh, im developing a leaderboard but i've got an error saying; "LeaderboardHandler:22: attempt to index string with 'Text'

How do i prevent this from happening?

local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")

local function updateLeaderboard()
    local success, errorMessage = pcall (function()
          local Data = WinsLeaderboard:GetSortedAsync(false, 5)
          local WinsPage = Data:GetCurrentPage()
           for Rank, data in ipairs(WinsPage) do
               local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
               local NameX = userName
               local Cash = data.value
               local isOnLeaderboard = false
               for i, v in pairs(workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
                   if v.Player.Text == NameX then
                       isOnLeaderboard = true
                       break
                    end
                end

                if Cash and isOnLeaderboard == false then
                    local newLbFrame = game.ReplicatedStorage.LeaderboardFrame:Clone()
                    newLbFrame.Name.Text = NameX
                    newLbFrame.Cash.Text = Cash 
                    newLbFrame.Rank.Text = "#"..Rank
                    newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
                end
            end
       end)

    if not success then
        print(errorMessage)
    end
end

while true do

        for _, player in pairs(game.Players:GetPlayers()) do
              WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Cash.Value)
        end

        for _, frame in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
             frame:Destroy()
        end

        updateLeaderboard()
        print("Updated!")

        wait(10)
end

1 answer

Log in to vote
2
Answered by
iOwn_You 543 Moderation Voter
4 years ago
Edited 4 years ago

Your problem is that you have an instance named “Name” You cant call it like that;

You should either do newLbFrams[“Name”].Text to get the instance or you should just name it “name” instead.

Right now its trying to get to its name and then find another property called “Text” which doesnt exist.

0
I am pretty sure you can also use FindFirstChild("Name") or WaitForChild("Name"), but it's true. The script is referring to the property Name, not the child Name. LightningLIon58 49 — 4y
0
You could, but its shorter to write what I sent and you dont need findfirst or waitfor because its an instance created with studio, its surely there. iOwn_You 543 — 4y
Ad

Answer this question