Again Problem with datastore

  1. What do you want to achieve? Keep it simple and clear!
    Lmao this is my third topic about that, i can’t save data i declare it path properly but data goes unsuccess.
  2. What is the issue? Include screenshots / videos if possible!
    Data do not save
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to declare path by different ways, but only the way which work is leaderstats folder, but not a stats folder

Script:

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local clicks = Instance.new("IntValue")
	clicks.Name = "Clicks"
	clicks.Parent = leaderstats

	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats

	local PlayerGUI = player:WaitForChild("PlayerGui")
	local StatsFolder = PlayerGUI:WaitForChild("Stats")
	local RCAmount = StatsFolder:WaitForChild("RCAmount")
	local Memory = StatsFolder:WaitForChild("Memory")
	local MemoryLevel = StatsFolder:WaitForChild("MemoryLevel")
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				clicks.Value = result[1]
				money.Value = result[2]
				rebirths.Value = result[3]	
				RCAmount.Value = result[4]
				Memory.Value = result[5]
				MemoryLevel.Value = result[6]
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		local PlayerGui = player:WaitForChild("PlayerGui")
		local StatsFolder = PlayerGui:WaitForChild("Stats")
		local Memory = StatsFolder:WaitForChild("Memory")
		local MemoryLevel = StatsFolder:WaitForChild("MemoryLevel")
		return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, MemoryLevel.Value, Memory.Value})
	end)

	if success then
		print(result)
		print()
	else
		warn(result)
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			local PlayerGui = player:WaitForChild("PlayerGui")
			local StatsFolder = PlayerGui:WaitForChild("Stats")
			local Memory = StatsFolder:WaitForChild("Memory")
			local MemoryLevel = StatsFolder:WaitForChild("MemoryLevel")
			return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, MemoryLevel.Value, Memory.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

These are something to make it like easier to save.

So when loading and saving it instead of having like data[1] = clicks for example you could have data[“Clicks”] = click then it would make it easier to load it in. So you can just loop through the table and add the data you want instead of manually doing it for every single variable.

Same goes with the saving, you could loop through the players data and add it to a table like data[VariableName] = VariableValue so you don’t have to do that manually either.

It is not a problem, problem is what when i’m trying to get a value from other paths except leaderstats datastore instantly break

I understand that was not the problem, just wanted to say that so you could make it easier to save in the future.

But could you like explain a little what you mean break. Does it not succeed with the pcall, does it not add the expected value or what do you mean with that.

I will just go into studio and check it out if I could figure something out :))

It just do not save data when i use different path except leaderstats. When i use waitforchild i just don’t get a warn error(if i don’t use i instantly get error “data not success”)

Okay, I will go into studio and see first then I will see if I could get the solution.

image
here instantly error when i remove wait for child

Are the values being created on the server or on the client?

Nvm, it is the folder/ ScreenGui I guess. Okay, so is the folder/ screenGui created before the game starts or in a script (server or client?)?

Okay, so the thing is that it works perfectly fine for me. How did you create the values? Are they created before the game starts, are they crated with a LocalScript or are they created with a ServerScript?

I created them before the game in studio
image

They created before game start

Okay, then that is a little weird because same for me and everything works fine…

Edit: Did you spell everything correctly and things?

Really weird my data just do not save

I’am sure
image

Did you spell for example the folder “Stats” correctly?

Hmm, okay. Let me see if I can come up with something then.

There isn’t a chance that there is another object like a ScreenGui in the StarterGui named “Stats”?

No this is not possible here is path:
image

Hmm, I don’t really know what the problem could be then since everything works fine for me. Maybe someone else has the same problem when testing so they might have a solution but I don’t in this situation sadly.

U just used my script yes? And your path is same? Maybe smth wrong with path

Yeah, I used everything the same as you. Copied the script and where everything was located. So I am sorry but I don’t really have a solution now. If I can come up with something later I can see if that could work.