I don't understand why my datasave doesn't work for a IntValue

  1. What do you want to achieve? Hello, I have a problem that persists with my script for the datasave, I can not save the boolvalue in the name of Donator that you can find on the script below. I can save the Creature folder (Data[1]) but not the other one (Data[2]). Could you help me to understand why it doesn’t work? I put you the GetAsync part and the SetAsync part. Thank you

  2. What is the issue?

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

	local donation = Instance.new("IntValue")
	donation.Parent = plr
	donation.Name = "Donator"

	local data = SaveData:GetAsync(plr.UserId)

	if data then 
		for _, creature in pairs(data) do
			if workspace.Creatures:FindFirstChild(creature) then
				local bool = Instance.new("BoolValue")
				bool.Name = creature
				bool.Parent = creatures
				creature = data[1]
				for i,v in pairs(game.Workspace.Creatures:GetChildren()) do
					v.CanTouch = true
				end
			end
		end
		donation.Value = data[2]
		for i,v in pairs(game.Workspace.Creatures:GetChildren()) do
			v.CanTouch = true
		end
------------------------------------------------------------------------
local CreaturesName = {}
	for _, creature in pairs(plr.Creatures:GetChildren()) do
		table.insert(CreaturesName, creature.Name)
	end
	table.insert(CreaturesName, plr.Donator.Value)
	SaveData:SetAsync(plr.UserId, CreaturesName)
end)

please help normally the script should be very close to working. In fact, I can’t understand why it doesn’t work

Could you try adding a print(CreaturesName) at the end right before "SaveData:SetAsyn(plr.UserId, CreaturesName)

How is that table looking is it ok ?

And then add another print at the top Right after loading the Datastore in your data variable.
print(data)

Tell me how it looks

Oh!

for _, creature in pairs(data) do

There you place Data[_] inside creature and then 5 lines later you overwrite it with
“creature = data[1]”

So basically if the 2 was intvalue you overwrote it with Data[1]…

Yes sur, first line is GetAsync Data, last line is just before SetAsync. x7 is because they are 7 boolvalues in the Creatures Folder
Capture

The DataSave of the folder Creatures is working, but the IntValue Donation doesn’t work. I also removed this lines in the script because she has no sense

creature = data[1]

Yes well you tell the script that Donator.Value = data[2] but you’re telling me you have 7 creatures which means Donator would be on position 8 ?

In that for loop you should replace _ with i and use data[i] instead of assuming a 1 or a 2…

But to do that you would need a if to determine if the place where you are in the for is a creature or a donator.value

In fact, there are hundreds of creatures that the player must collect. So as you go along it will be x1, x2 […] x100 .

maybe I should separate the plr.Donature.Value and the Creature Folder in two SetAsync ? I will try

Either you separate it or you figure out a way to detect whether or not it is a creature or the last line.

if ( (creature == 1) or (creature == 0) then
print(“it is a donator value”)
else
print(“it is a creature”)
end