Why isnt my Datastore saving my stats?

Handler Script

local DataStore = game:GetService("DataStoreService")

local StatsDataStore = DataStore:GetOrderedDataStore("key go buur") --Make It Hard So Hacker Cant Guess It

local ResetTime = script.Parent.TimeUntilReset
local Time = script.Parent.Time.Value
Time = 5
while wait(1) do
	Time = Time - 1 
	script.Parent.Parent.ResetTime.TextLabel.Text = "Resetting in " .. Time .. " seconds..."
	if Time == 0 then Time = ResetTime.Value
		for i, plr in pairs(game.Players:GetPlayers()) do	
			StatsDataStore:SetAsync(plr.UserId, plr.leaderstats:FindFirstChild(script.Parent.Parent.Stats.Value).Value) 
		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
			if leaderboardRank.ClassName == "Frame" then

		local success, errorMsg = pcall(function()
			local data = StatsDataStore:GetSortedAsync(false, script.Parent.PlayerInLB.Value)
			local StatsPage = data:GetCurrentPage()
			for rankInLB, dataStored in ipairs(StatsPage) do
				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local id = tonumber(dataStored.key)
				local statsname = dataStored.value
				local Gui = script.Top:Clone()
				Gui.PlrName.Text = name
				Gui.Rank.Text = "#" .. rankInLB
				Gui.Amount.Text = statsname
				Gui.Parent = script.Parent	
				if Gui.Rank.Text == "#1" then
					Gui.Color.Value = Color3.fromRGB(255, 255, 0) --Top 1 Background Color
					script.Parent.Parent.Parent.Parent.Top1.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top1.Tags.Container.pName.Text = name
				if Gui.Rank.Text == "#2" then
					Gui.Color.Value = Color3.fromRGB(98, 98, 98) --Top 2 Background Color
					script.Parent.Parent.Parent.Parent.Top2.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top2.Tags.Container.pName.Text = name
				if Gui.Rank.Text == "#3" then
					Gui.Color.Value = Color3.fromRGB(255, 85, 0) --Top 3 Background Color
					script.Parent.Parent.Parent.Parent.Top3.Configuration.userId.Value = id
					script.Parent.Parent.Parent.Parent.Top3.Tags.Container.pName.Text = name	

LeaderStats Script

local DataStore = game:GetService("DataStoreService")
local StatsDataStore = DataStore:GetDataStore("Kvhyj76455242")

function onPlayerEntered(newPlayer)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"

	local thing = Instance.new("IntValue")
	thing.Name = script.Parent.Part.BillboardGui.Stats.Value
	thing.Value = StatsDataStore:GetAsync(newPlayer.UserId) or 0
    thing.Parent = stats
	stats.Parent = newPlayer


Detect change script

script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value

	script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value

Any help please?

i believe findifrstchild returns bool?

i cant even save data using numbers

this is spamming the datastore and will throw an error

It is finding the first child of the value which is the name of the store that I have

Instead of writing “script.Parent” and so on, try making variables so it’s easier for you and others to read.

This is from a tutorial I found online. I did not write the script.Parent’s. I have plan to fix after finding out this issue

How long ago was this video made, and what is the script supposed to do?

The script is supposed to make a leader stats that connects to a leaderboard. Example, it displays the Top Three Players on that board Player 1 = 5 wins (1st place) player 2 = 3 (2nd) and so on.

what is this? hackers can’t access datastores unless they backdoor the Roblox Servers in which case it doesn’t matter what you name your key

it is just a bunch of randomly generated numbers and letters

Edit: This was open-sourced code so I just needed to change a few things after finding the issue

hackers can’t access, unless they can fire a remoteevent and get unlimited in-game currency


There are lots of things I want to ask and say.

  1. Is the leaderstats script a local script or server script?
  2. Is the handler script a local script or server script?

You shouldn’t save the player’s data quickly. There is a cooldown to write it to the data store. And also you are getting the ordered data store very quickly. You can change it to a higher number . You should save the players’ data in the another script.

while wait(1) do

Instead of this

while wait(60) do

Hackers can’t access data stores since they use only local scripts.

You should wrap this in a pcall.

You don’t need to use Text property. You can just use the rank

if tonumber(rankInLB) == 1 then
    -- any stuff

you have control over what remote events do, always use Sanity Checks on the server. Hackers can never directly access DataStores as I said, so there is no point in naming them mumbo jumbo.

If a hacker would have access to DataStore they would have access to the Roblox servers and do a lot more damage than mess up your game.

All scripts presented are server scripts. When I followed the YT Tutorial, on their side, it worked perfectly fine. If I add a wait, how will affect the scripts?

That’s why, you can only use and access datastore from Server Scripts.

Also as @ProBaturay you shouldn’t call the datastore too often because there is a budget

It’s best to do :GetAsync when a player joins and :SetAsync when they leave. If you are doing a global leaderboard you shouldn’t do :GetSorted more than once every minute.

1 Like

What do you mean? I already know the only way to get datastores is by server scripts.

You just said all scripts presented are LocalScripts

OH SHOOT. i did not even see that. my bad lol

I recommend you learn how the Client-Server model works


here’s a good video by AlvinBlox

and here’s a better tutorial on OrderedDatastore

Ok. Thanks for letting me know and thanks for the references.

1 Like