{FIX} with global table

  1. What do you want to achieve? We have a table {Rank-Player-Level} And it updates every 10 seconds

  2. What is the issue?

local DataStoreService = game:GetService("DataStoreService")
local levelLeaderboard = DataStoreService:GetOrderedDataStore("LevelLeaderboard")
local PositionUIBoard = game.Workspace.GlobalLeaderBoard.leaderBoardGUI.Holder

local  function updateLeaderboard ()
	local success, errorMessage = pcall(function()
		local Data =  levelLeaderboard:GetSortedAsync(false, 5)
		local levelPage = Data:GetCurrentPage()
		for RANK, data in ipairs(levelPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local level = data.value
			local isOnLeaderboard = false
while true do
	
	for _, player in pairs(game.Players:GetPlayers()) do
		levelLeaderboard:SetAsync(player.UserId, player.leaderstats1.level.Value)
	end
  1. What solutions have you tried so far? I looked it was connected with the data, but this is what was needed

You need to go to Game Settings > Permissions (Might be security, forgot the actual name) > And then enable studio access to API’s.

Keep in mind this is from memory, so I don’t know what the actual names are.

1 Like

Level 1
Did you mean this?

Sorry, no, this should be more clear:

To enable Studio access in a published experience:

  1. In the Home tab of the menu bar, navigate to the Settings section and click Game Settings. The Game Settings menu displays.

  2. In the left-hand navigation of the Game Settings menu, click Security.

  3. Enable the Enable Studio Access to API Services toggle.

  4. Click the Save button.

(Taken from Data Stores | Roblox Creator Documentation)

2 Likes

Ok, I’ll study the material right now {This is the first time I’ve come across this}

True, it turned out to be easy, but strangely, a new error appeared -


All script -

local DataStoreService = game:GetService("DataStoreService")
local levelLeaderboard = DataStoreService:GetOrderedDataStore("LevelLeaderboard")
local PositionUIBoard = game.Workspace.GlobalLeaderBoard.leaderBoardGUI.Holder

local  function updateLeaderboard ()
	local success, errorMessage = pcall(function()
		local Data =  levelLeaderboard:GetSortedAsync(false, 5)
		local levelPage = Data:GetCurrentPage()
		for RANK, data in ipairs(levelPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local level = data.value
			local isOnLeaderboard = false
			for i, v in pairs(PositionUIBoard:GetChildren() ) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if level and isOnLeaderboard == false then
				local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLBFrame.Player.Text = Name 
				newLBFrame.level.Text = level
				newLBFrame.RANK.Text = "#"..RANK
				newLBFrame.Position = UDim2.new(0,0, newLBFrame.Position.Y.Scale + (.08 * #PositionUIBoard:GetChildren()), 0)
				newLBFrame.Position = PositionUIBoard
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do
	
	for _, player in pairs(game.Players:GetPlayers()) do
		levelLeaderboard:SetAsync(player.UserId, player.leaderstats1.level.Value)
	end
	
	for _, frame in pairs(PositionUIBoard:GetChildren()) do 
		frame:Destroy()
	end
	
	updateLeaderboard()
	print ("Update!")
	
	wait(10)
end 

You meant to write “Parent” here

you are right about that…I will look for an answer

I fixed the mistake, nothing more stupid than I did, but we learn from mistakes, so thanks to everyone who helped me!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.