Data Store Script dont working ALREADY SOLVED

I made a leaderstats script but everytime the data store reset like 0 and dont save, i try everything but nothing works, i try change the names and values but nothing

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")
local DataLoad = game.ReplicatedStorage.Remotes:WaitForChild("DataLoad")

local StarterData = {
	Gold = 0,
	Level = 1,
	Energy = 0,
	EXP = 0,
	Gems = 0,
	EXPNeeded = 125,
	EnergyAddons = 1
}

game.Players.PlayerAdded:Connect(function(plr)

	local sucess, PlayerData = pcall(function()
		return DataStore:GetAsync(plr.UserId) or StarterData
	end)

	if sucess then
		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = plr

		local hidestats = Instance.new("Folder")
		hidestats.Name = "hidestats"
		hidestats.Parent = plr


		for Index, Value in pairs(PlayerData) do
			if Index ~= "EXPNeeded" and Index ~= "EXP" and Index ~= "EnergyAddons" then
				local NumberValue = Instance.new("IntValue")
				NumberValue.Parent = leaderstats
				NumberValue.Name = Index
				NumberValue.Value = Value
			else
				local NumberValue = Instance.new("IntValue")
				NumberValue.Parent = hidestats
				NumberValue.Name = Index
				NumberValue.Value = Value
			end
		end
		
		task.wait(1)
		DataLoad:FireClient(plr)
		
		hidestats.EXP.Changed:Connect(function()
			local expDefault = 125
			local expNeeded = expDefault * leaderstats.Level.Value
			if hidestats.EXP.Value >= expNeeded then
				hidestats.EXP.Value = 0
				plr.hidestats.EXPNeeded.Value =  expDefault * leaderstats.Level.Value
				leaderstats.Level.Value = leaderstats.Level.Value + 1
			end
		end)
	end

end)


game.Players.PlayerRemoving:Connect(function(plr)
	local PlayerData = {

	}

	for Index, Child in pairs(plr.leaderstats:GetChildren()and plr.hidestats:GetChildren()) do
		if Child:IsA("IntValue") then
			PlayerData[Child.Name] = Child.Value
			for index, value in StarterData do
				if PlayerData[index] == nil then
					PlayerData[index] = value
				end
			end
			
		end
	end
	
	pcall(function()
		DataStore:SetAsync(plr.UserId, PlayerData)
	end)

end)

You have two for loops here, the second one ovewriting parts of the table with default values. Try removing it and putting it after the first for loop.

That’s an extremely weird way of joining two tables together, have you considered using table.move

Also, are there any errors returned during runtime? Does the saving successfully go through?

thats what i made first, i try realocate the for but nothing, the error its the data dont save and when i join everything come back to 0

Its important to note that DataStores usually do not work in roblox studio testing. Try testing in a live game.

Also make sure you have the DataStore box checked in game settings.

i already check and already testet out of studio and still dont work