Problem with saving a value(others save normally)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So basically i have datastore with 13 results of data. 12 works fine, but last one works glitchy for some reason. It just do not save data. It always gave me a zero, i checked fifteen times everything, every line , but didn’t figure a reason. So to remove a zero(bcz i use that value to multiply an other value) i made a
rcmulticlicks.Value = result[11] or 1

but it just always give me 1, that means data is nothing. I do not get any error with my prints(bcz when i have error, my game prints what something wrong with data)
2. What is the issue? Include screenshots / videos if possible!
1st
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i checked all my code many times, tryed to find any script which sets value to zero, but when i added

or 1

value become 1

My code:

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

local protectedCall = pcall

local function onPlayerJoined(player)
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = 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 memory = Instance.new("IntValue")
	memory.Name = "Memory"
	memory.Parent = StatsFolder
	
	local memorylevel = Instance.new("IntValue")
	memorylevel.Name = "MemoryLevel"
	memorylevel.Parent = StatsFolder
	
	local mouselevel = Instance.new("IntValue")
	mouselevel.Name = "MouseLevel"
	mouselevel.Parent = StatsFolder
	
	local rcamount = Instance.new("IntValue")
	rcamount.Name = "RCAmount"
	rcamount.Parent = StatsFolder
	
	local rcmultimoney = Instance.new("NumberValue")
	rcmultimoney.Name = "RCMultiMoney"
	rcmultimoney.Parent = StatsFolder
	
	local rcmulticlicks = Instance.new("NumberValue")
	rcmulticlicks.Name = "RCMultiClicks"
	rcmulticlicks.Parent = StatsFolder
	
	local rc1collected = Instance.new("BoolValue")
	rc1collected.Name = "RC1Col"
	rc1collected.Parent = StatsFolder
	
	local rc2collected = Instance.new("BoolValue")
	rc2collected.Name = "RC2Col"
	rc2collected.Parent = StatsFolder
	
	local moneyfromtrade = Instance.new("NumberValue")
	moneyfromtrade.Name = "MoneyFT"
	moneyfromtrade.Parent = StatsFolder
	
	local clicksperclick = Instance.new("NumberValue")
	clicksperclick.Name = "ClicksPerClick"
	clicksperclick.Parent = StatsFolder
	
	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]	
				memory.Value = result[4]
				memorylevel.Value = result[5]
				mouselevel.Value = result[6]
				rcamount.Value = result[7]
				rcmultimoney.Value = result[8]
				rc1collected.Value = result[9]
				moneyfromtrade.Value = result[10]
				rcmulticlicks.Value = result[11] or 1
				clicksperclick.Value = result[12]
				rc1collected.Value = result[13]
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RCMultiClicks.Value, player.Stats.RC1Col.Value, player.Stats.RC2Col.Value, player.Stats.MoneyFT.Value, player.Stats.ClicksPerClick.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RCMultiClicks.Value, player.Stats.RC1Col.Value, player.Stats.RC2Col.Value, player.Stats.MoneyFT.Value,  player.Stats.ClicksPerClick.Value})
		end)

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

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

Note. That value being change by SERVER not by CLIENT. Don’t write me about that. Thanks!

make a print before you do the save to check the current value of rcmulticlicks and tell me what you get

It looks like the last 5 table entries when your saving the data is mixed up:

clicks.Value = result[1] -----> player.leaderstats.Clicks.Value
money.Value = result[2] -----> player.leaderstats.Money.Value
rebirths.Value = result[3] -----> player.leaderstats.Rebirths.Value	
memory.Value = result[4] -----> player.Stats.Memory.Value
memorylevel.Value = result[5] -----> player.Stats.MemoryLevel.Value
mouselevel.Value = result[6] -----> player.Stats.MouseLevel.Value
rcamount.Value = result[7] -----> player.Stats.RCAmount.Value
rcmultimoney.Value = result[8] -----> player.Stats.RCMultiMoney.Value
rc1collected.Value = result[9] -----> player.Stats.RCMultiClicks.Value
moneyfromtrade.Value = result[10] -----> player.Stats.RC1Col.Value
rcmulticlicks.Value = result[11] or 1 -----> player.Stats.RC2Col.Value
clicksperclick.Value = result[12] -----> player.Stats.MoneyFT.Value
rc1collected.Value = result[13] -----> player.Stats.ClicksPerClick.Value

EDIT: also just noticed rc1collected.Value is being used twice, shouldn’t the bottom one be rc2collected.Value?

1 Like

image
Data which saves
image
Data which was added to value

1 Like

I do not think so… Bcz data save normally

{player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RCMultiClicks.Value, player.Stats.RC1Col.Value, player.Stats.RC2Col.Value, player.Stats.MoneyFT.Value, player.Stats.ClicksPerClick.Value}),

if you count along, you’ll see that RCmulticlicks is at position 9, whereas you’re loading rc multiclicks at position 11

Same thing. Still getting zero by a print

Lemme check again that thing… maybe i again write smth wrong

return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RC1Col.Value, player.Stats.MoneyFT.Value, player.Stats.RCMultiClicks.Value, player.Stats.ClicksPerClick.Value, player.Stats.RC2Col.Value})

try this

Oh i just made that myself, my data was really mixed up and a lot of other data didn’t work(like it was saving smth and i thought it works), i didn’t knew what result could mix up, thanks i will remember that

1 Like
if type(result) == "table" then
				clicks.Value = result[1]
				money.Value = result[2]
				rebirths.Value = result[3]	
				memory.Value = result[4]
				memorylevel.Value = result[5]
				mouselevel.Value = result[6]
				rcamount.Value = result[7]
				rcmultimoney.Value = result[8]
				rc1collected.Value = result[10]
				moneyfromtrade.Value = result[12]
				rcmulticlicks.Value = result[9] or 1
				clicksperclick.Value = result[13]
				rc2collected.Value = result[11]
			end