Datastore saving failure

  1. What do you want to achieve?
    I’m attempting to create a datastore saving system that stores intvalue leaderboardstats and stringvalues for skins I’ve made in-game. I’m trying to familiarize myself with datastore as I’ve not have much experience with it.

  2. What is the issue?
    Previously, when the script only saved leaderboard stats, it worked perfectly. However, ever since I modified it to save stringvalues, the script no longer works.

  3. What solutions have you tried so far?
    I’ve tried playing around with jsonencode and other possibilities. However, now even if I rewrite the script to how it was before or even separate the two values into two different datastores, this portion of the script never runs properly.

local function PointSave(player)
	local Point1 = player:WaitForChild("leaderstats").Glory.Value
	local Point2 = player:WaitForChild("leaderstats").Wins.Value
	local Skins = player:WaitForChild("Skins")
	local SavedSkins = {}
	for i, v in pairs(Skins:GetChildren()) do
		table.insert(SavedSkins, v.Value)
	local DataTable = {
	local Success, Error = pcall(function()
		print("Working") -- prints
		LeaderboardStats:SetAsync(player.UserId, DataTable) -- I assume this is where it fails to run
		print("DoubleChecking") -- Doesn't print?

	if Success then

This is a portion of the current script I have, each line runs until it hits SetAsync. Which no longer seems to work? Nothing errors, but the data is never saved. I’d appreciate any help as I don’t understand what’s going wrong?

Strangely, after some more testing, the script seems to run fine whenever tested in a local server. So it may be an issue with Roblox Studio? However, this runs the problem that I’m unable to test the datastore in regular studio and have to constantly use a local server, where data doesn’t save between each test. Is there any solution to this or do I just have to constantly switch between studio and the live game?

Add this to the end of your datastore code.

   if game:GetService("RunService"):IsStudio() then
1 Like

Thank you! It instantly solved the issue. For the sake of my understanding, what exactly does this code do? I’m assuming it delays the server for two ticks?

Since the game closes since you are the last player, the data dosent properly save (data issues), what this does is delay the closure of the server for two seconds so the data can properly save.

Setting the value above a specific number can break the script.

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