Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

2 comments

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.