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

ServerScriptService.Leaderboard:26: attempt to index string with 'Text'?

Asked by 4 years ago

this is my leaderboard script, unfortunately the script is giving this error

""ServerScriptService.Leaderboard:26: attempt to index string with 'Text'

I do not know how to fix it, look at some of the variables then skip to line 26!

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 Name = userName
                       local Wins = data.value
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.GlobalLeaderBoard.SurfaceGui.Holder:GetChildren()) do
                             if v.Player.Text == Name then
                                  isOnLeaderboard = true
                                break
                           end
                    end

                     if Wins and isOnLeaderboard == false then

    local newLbFrame = game.ReplicatedStorage.LeaderboardFrame:Clone()
                            local Nam = newLbFrame.Name
                            local Ran = newLbFrame.Rank
                            local Win = newLbFrame.Wins
                            Nam.Text = Name
                            Win.Text = Wins 
                            Ran.Text = "#"..Rank
                            newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderBoard.SurfaceGui.Holder:GetChildren()), 0)
                            newLbFrame.Parent = game.Workspace.GlobalLeaderBoard.SurfaceGui.Holder
                     end
              end
      end)

      if not success then
          warn(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.SurfaceGui.Holder:GetChildren()) do
             frame:Destroy()
        end

        updateLeaderboard()
        print("Updated!")

        wait(10)
end

1 answer

Log in to vote
2
Answered by 4 years ago

The problem is when there is a child named Name, it conflicts with the property that the instance has. Roblox by default indexes the property. The solution is to rename the TextLabel into something else.

local newLbFrame = game.ReplicatedStorage.LeaderboardFrame:Clone()
local Nam = newLbFrame.Name -- Rename this into something else (example: PlayerName)
local Ran = newLbFrame.Rank
local Win = newLbFrame.Wins
Nam.Text = Name
Win.Text = Wins
Ran.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderBoard.SurfaceGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.GlobalLeaderBoard.SurfaceGui.Holder
Ad

Answer this question