Data won't load

I have absolutely no idea what I did. I literally just typed like 3 random words and it works now lol


Here is the working script back

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 data
	
	local success, errorMessage = pcall(function()
		data = PartsStore:GetAsync(player.UserId.."-Data")
	end)
	
	if success then
		Parts.Value = data --What's not running.
		print("Loaded data")
	else
		warn("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
		warn("Data Fricked Up")
	end
end)

function onShutDown()
	task.wait(4)
end

game:BindToClose(onShutDown)

Doesn’t work for me, the data isn’t loading. It says it is but it’s just 0.

its because of this line
i fixed it so try it now

local success, errorMessage = pcall(function()
		PartsStore:SetAsync(playerUserID, player.leaderstats.Parts.Value) -- this line (fixed)
	end)

Did you change the value back? It was still saving, so it saved the original number. But if you joined again, it didn’t load and set it to 0, so upon leaving it saved as 0

You need to set the number back

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]
	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)

That didn’t work. Can data saving be messed up by ones computer/studio settings?

No, I didn’t. The only scripts outside of stats are just making parts. They only add to the player’s parts.

local PartsStore = DataStoreService:GetDataStore("PlayerParts") -- change the PlayerParts to another string and try again

this works completly fine for me.

That’s weird, it doesn’t for me.

I think I should mention that at when I create the data variable, it’s an error since it isn’t local.

That’s strange. It works just fine for me.

Do those scripts run locally? (I ask since I didn’t look at or touch any of the other scripts.) Because if they are, there is your main problem. The stat needs to be changed on the server else it won’t save.

If they aren’t running locally, I have no idea what your problem could be.

I recorded a video of it working for me, lemme trim it down and I’ll attach it in a couple minutes.

can you change “PlayerParts” DataStore string to another string?

The reason nothing was working was cause I was changing the player’s Parts locally. It works now that I used a remoteEvent. I’m sorry. :sweat_smile:

oh then glad that you got it to work :smiley:

Gosh lol.

It’s completely fine, everyone makes silly mistakes like that at some point.
Funnily enough though, even before I did anything with the script it didn’t load (and I did change it on the server.) So, I did do something. Don’t really know what, but I did lol (I paid no attention to what I typed. I added random words and it worked)