My issue is that, I have a datastore script that creates a leaderstat folder inside a player, and to save the intvalue inside it, titled as Minutes. The script is successful and fully functional. The issuse comes in ordered datastore. I managed to script a ordered datastore to create a physical leaderboard that defines the person that has the most play-time / minutes in the game. Script is fully functional, but the problem with it is that we cannot detect the minute value from the original datastore script and put it on the leaderboard. And I don’t know what to do in result.
The regular datastore;
--{| Services |}--
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStatus")
--{| Functions |}--
game.Players.PlayerAdded:Connect(function(Player)
--|| LeaderStats ||--
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Minutes" -- IntValue Title.
Minutes.Value = 0 -- Default Value.
Minutes.Parent = Player.leaderstats
--{|| DataStore ||}--
local Data = DataStore:GetAsync(Player.UserId) -- Get Data.
if type(Data) ~= "table" then Data = nil end
if Data then Minutes.Value = Data.Minutes end
coroutine.resume(coroutine.create(function()
while true do
wait(60) -- Wait every minute.
Minutes.Value = Minutes.Value + 1
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId,{Minutes = Player.leaderstats.Minutes.Value})
end)
The ordered datastore;
--||Services||-
local DataStoreService = game:GetService("DataStoreService")
-- Settings [Variables]
local Update_Time = 15
--||Variables||--
local TimeStatusDStore = DataStoreService:GetOrderedDataStore("Minutes")
local MostPlayedGUI = workspace.Boards.MostPlayed.MostPlayedGUI
local MP_List = MostPlayedGUI.Status_List
local BestEmployee = workspace.Boards.BestEmployee.MostPlayedPortrait
--||Functions||--
local function GetItems()
local Data = TimeStatusDStore:GetSortedAsync(false, 10)
local TopList = Data:GetCurrentPage()
for rank, data in ipairs(TopList) do
local UserId = data.key
local Value = data.value
local Username = "[Not Avaliable.]"
local UserImg = "rbxasset://textures/ui/GuiImagePlaceholder.png"
local Success, ErrorMessage = pcall(function()
Username = game.Players:GetNameFromUserIdAsync(UserId)
UserImg = game.Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
end)
if rank == 1 then
BestEmployee.MainFrame.Player_Title.Text = UserId
BestEmployee.MainFrame.Player_Image.Image = UserImg
end
MP_List["PlayerFrame_".. rank].Player_Title.Text = UserId
MP_List["PlayerFrame_".. rank].Play_Time.Text = Value .. " Minutes."
MP_List["PlayerFrame_".. rank].Player_Image.Image = UserImg
end
end
while true do
wait(Update_Time)
for i, v in pairs(game.Players:GetPlayers()) do
local Stat = v.leaderstats:WaitForChild("Minutes")
if Stat then pcall(function() TimeStatusDStore:UpdateAsync(v.UserId, function(Value) return tonumber(Stat) end) end) end
GetItems()
end
end
Does anyone have a solution to this madness.