GetPlayers is not a valid member of DataModel?

Hi There!!

Today I have been working on a Global Leaderboard. I am still learning to develop, so I watched this video:
https://www.youtube.com/watch?v=sXpuGnVzsxw

When I finished, I got this error:
image
I watched the video to see if he got the error, but he did not so I came here.

My script:

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

local function updateLeaderboard()
	local succes, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
		for rank, data in ipairs(WinsPage) do
			local userName = game.GetPlayers:GetNameFromUserIdAsync(tonumber(data.key))
			local name = userName
			local Wins = data.value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if Wins and isOnLeaderboard == false then
				local newLeaderboardFrame = game.ReplicatedStorage:WaitForChild("LeaderBoardFrame"):Clone()
				newLeaderboardFrame.Player.Text = Name
				newLeaderboardFrame.Wins.Text = Wins
				newLeaderboardFrame.Rank.Text = "#"..Rank
				newLeaderboardFrame.Position = UDim2.new(0, 0, newLeaderboardFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder:GetChildren()), 0)
				newLeaderboardFrame.Parent = game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder
			end
		end
	end)
	
	if not succes then
		print(errorMessage)
	end
end

while true do
	
	for _, player in pairs(game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
	end
	
	for _, frame in pairs(game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboard()
	print("Updated!")
	
	wait(10)
end

If you want any more details, just tell me and I will post back!!

hope you can help!!

here is a video:

https://drive.google.com/drive/u/0/folders/1Nk8vdKowZn-_Sewk3DozJMAKyS4xrG9I

I ran your code it works fine.
What line did it caused GetPlayers is not valid member of DataModel?

1 Like

Try using

game:GetService("Players"):GetPlayers()

Edit:

You said

local userName = game.GetPlayers:GetNameFromUserIdAsync(tonumber(data.key));

--<Should be:

game:GetService("Players"):GetNameFromUserId(tonumber(data.key));
--I think that's your problem
1 Like

I do not know what line is wrong, when I click it, it just takes me to the script above.

DataModel is the roblox game object. It’s children are roblox services like workspace, players, lighting, etc.

Here’s the problem:
local userName = game.GetPlayers:GetNameFromUserIdAsync(tonumber(data.key))

GetPlayers() is a function of game.Players or game:GetService('Players'). But not game

1 Like