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
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.