Data won't load

I am writing a leaderstats script and I have the datastore but it won’t load for some reason.
I have a “Parts” = data.
Here is my script:

local DataStoreService = game:GetService("DataStoreService")

local PartsStore = DataStoreService:GetDataStore("PlayerParts")

game:GetService("Players").PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local PartColor = Instance.new("Color3Value", leaderstats)
	PartColor.Name = "Color"
	PartColor.Value = Color3.new(255,255,255)
	local Parts = Instance.new("IntValue", leaderstats)
	Parts.Name = "Parts"

	local playerUserID = ("Player_" ..  player.UserId)
	
	local success, errorMessage = pcall(function()
		data = PartsStore:GetAsync(playerUserID)
	end)
if success then
		Parts.Value = data --What's not running.
	else
		print("Player's data wen't no")
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local playerUserID = ("Player_" .. player.UserId)

	local data = player.leaderstats.Parts.Value

	local success, errorMessage = pcall(function()
		PartsStore:SetAsync(playerUserID, data)
	end)
	if success then
		print("Data Saved")
	else
		print("Data Fricked Up")
	end
end)

function onShutDown()
	task.wait(4)
end

game:BindToClose(onShutDown)

I used a print and everything is running. It is saving the data, loading it, and printing the “Parts” value afterwards. I don’t know what’s wrong

its because you’re already setting the value to Color3.new(255,255,255) when the players joins

I am only saving the parts variable right now.

The PartColor variable isn’t an issue because I’m not saving it.

I’m not seeing anything wrong, but I also didn’t fully read it. I only glanced, so I may have missed something.


Are you receiving any errors? If not, check to see if “Enable Studio Access to API Services” is enabled.

If you are not receiving errors and API access is enabled, tell me and I’ll do a deeper read. I just woke up, so I’m a little tired, which is why I didn’t the first time lol.

Yes API is enabled. I’m not seeing any error messages related to the script. It’s just showing it is running. Here is my output, mainly look at the bottom.

  08:57:36.315  Requiring asset 512742721.
Callstack:
cloud_8428896693.archimedesTwo.initiatePlugin.MainModule, line 29
cloud_8428896693.archimedesTwo.initiatePlugin.MainModule, line 28
  -  Server
  08:57:36.376  loadstring() is not available  -  Server
  08:57:36.376  Stack Begin  -  Studio
  08:57:36.376  Script 'cloud_183586902.Build v4.1.Plugin', Line 30 - function LoadResource  -  Studio
  08:57:36.376  Script 'cloud_183586902.Build v4.1.Plugin', Line 32  -  Studio
  08:57:36.376  Stack End  -  Studio
  08:57:36.395  Requiring asset 518094091.
Callstack:
cloud_8428896693.archimedesTwo.initiatePlugin.MainModule, line 30
cloud_8428896693.archimedesTwo.initiatePlugin.MainModule, line 28
  -  Server
  08:57:37.201  loadstring() is not available  -  Client
  08:57:37.202  Stack Begin  -  Studio
  08:57:37.202  Script 'cloud_183586902.Build v4.1.Plugin', Line 30 - function LoadResource  -  Studio
  08:57:37.202  Script 'cloud_183586902.Build v4.1.Plugin', Line 32  -  Studio
  08:57:37.202  Stack End  -  Studio
  08:57:37.203  Player Data Loaded  -  Server - Stats:21
  08:57:37.203  Parts == 0  -  Server - Stats:23
  08:57:39.963  Disconnect from ::ffff:127.0.0.1|53963  -  Studio
  08:57:40.143  Data Saved  -  Server

Hmm, okay that is strange.

Have you tried increasing your stats on the server side (in studio, or optionally in game with the console?)

If you have not, try that. If you have, would you be comfortable with sharing the game file (like, saving the game as a file (if it already isn’t)) and then send it to me? If not, that’s perfectly fine and understandable, it just makes it much easier to help.

can you add a print in the success?

if success then
        print("yes")
		Parts.Value = data --What's not running.
	else
		print("Player's data wen't no")
	end
end)

I added a print there to test already. It is running.

did you try to print the data though?

No, I will try that. But the data stat has an error because it’s not local, and there are apparently “no uses” of it outside the if statement.

Ok, it looks like it’s not saving correctly.

I have maximum studio stats so I don’t think that’d be the problem. Also I don’t know how to get a game file, sorry.

To get the game file, it is pretty simple.

Inside of the game on Studio, click File → Save to File as → name the file and save it to your computer, then simply send it here!

And, if you aren’t comfortable with it being completely open, you can always direct message it to me!

try this

local DataStoreService = game:GetService("DataStoreService")

local PartsStore = DataStoreService:GetDataStore("PlayerParts")

game:GetService("Players").PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local PartColor = Instance.new("Color3Value", leaderstats)
	PartColor.Name = "Color"
	PartColor.Value = Color3.new(255,255,255)
	local Parts = Instance.new("IntValue", leaderstats)
	Parts.Name = "Parts"

	
	local success, errorMessage = pcall(function()
		data = PartsStore:GetAsync(player.UserId.."-Data")
	end)
if success then
		Parts.Value = data [1] --What's not running.
	else
		print("Player's data wen't no")
	end
end)
game.Players.PlayerRemoving:Connect(function(player)


	local success, errorMessage = pcall(function()
		PartsStore:SetAsync(player.UserId.."-Data", {player.leaderstats.Parts.Value})
	end)
	if success then
		print("Data Saved")
	else
		print("Data Fricked Up")
	end
end)

function onShutDown()
	task.wait(4)
end

game:BindToClose(onShutDown)

I only see publish as and save as.

It should be directly above “Save to Roblox.”
If you don’t see it, try pressing Ctrl + Shift + S (the hotkeys to save it as a file)

That did the same thing. Hm.


Here, I downloaded a copy instead.
file.rbxl (54.6 KB)

Alrighty, that works too!! Thank you, should definitely help with fixing it lol.