One Line of Data Wont Save Because ' value cannot be converted to a number '

Up until this point, the saving and loading has been working fine. However, with the newest value (3), it suddenly wont save because the ‘value cannot be converted to a number.’ All of the other values are saving fine, and 3 is an int value with the same parameters as all of the other values. What might be causing this error?

local dss = game:GetService("DataStoreService")
local playerdata = dss:GetDataStore("123Save123")

---------- Player Statistics ----------
local One = game.ReplicatedStorage.One
local Two = game.ReplicatedStorage.Two
local Three = game.ReplicatedStorage.Three

game.Players.PlayerAdded:Connect (function(player)
	player.CharacterAdded:Connect (function(character)
		
		------- Load Data ---------------------------------
		local data = playerdata:GetAsync(player.UserId)
		
		if data ~= nil then
			One.Value = data["One"]
			Two.Value = data["Two"]
			Three.Value = data["Three"]
		else
			local success,err = pcall(function()
				playerdata:SetAsync(player.UserId,startData)
			end)
			if success then
			else
			end
		end
		
		------- Save Game ----------------------------------------
		game.OnClose = function()
			local saveData = {
				["One"] = One.Value,
				["Two"] = Two.Value,
				["Three"] = Three.Value
			}
			local success,err = pcall(function()
				playerdata:UpdateAsync(player.UserId, saveData)
			end)
		end
	end)
end)

When printed, the value is always “0” just like the others, so I am not positive what is setting it apart.

Refrain from doing this, try using names that don’t start with a number.
Like so;

local _1 = game.ReplicatedStorage._1

1 Like

To add on to what @Nitefal said, if you do use a number make sure to use [1] so that it treats it like a value, I’m not 100% sure what [] does but I know that it will make sure the script treats it like a string and not a number. I do not believe it works with variables though.

local one = game.ReplicatedStorage[1]
local two = game.ReplicatedStorage[2]
local three = game.ReplicatedStorage[3]

Changed it to words (one, two, three). Still the same problem. Thank you though.

@SlayterZ, I’m not sure if this will help, but if the “One, Two, and Three” Values are only being accessed by the Server, they do not need to be in ReplicatedStorage. Also:

local success,err = pcall(function()
	playerdata:SetAsync(player.UserId,startData) -- does startData exist???
end)

I do not see “startData” defined earlier in the script, am I missing something or is it not there?

I am pretty sure this is a Roblox bug. Other people (including myself) are also having the same issue despite making no script changes.

2 Likes

This must be the worst way ever to name keys.

Little mistake there

Sorry. Just trying to show an example of the simplified code so it’s easy to see. I’ll fix it.

I think I found the solution: Instance:FindFirstChild(number) now results in a warning

Not technically a bug, but a result of their update. It’s the player ID messing it up.

This is what I got to work:

local dss = game:GetService("DataStoreService")
local playerdata = dss:GetDataStore("123Save123")

---------- Player Statistics ----------
local One = game.ReplicatedStorage.One
local Two = game.ReplicatedStorage.Two
local Three = game.ReplicatedStorage.Three

game.Players.PlayerAdded:Connect (function(player)
	player.CharacterAdded:Connect (function(character)

		------- Load Data ---------------------------------
		local data = playerdata:GetAsync(tostring(player.UserId))

		if data ~= nil then
			One.Value = data["One"]
			Two.Value = data["Two"]
			Three.Value = data["Three"]
		else
		end

		------- Save Game ----------------------------------------
		game:BindToClose(function()
			local saveData = {
				["One"] = One.Value,
				["Two"] = Two.Value,
				["Three"] = Three.Value
			}
			local success, err = pcall(function()
				playerdata:SetAsync(tostring(player.UserId), saveData)
			end)
			if not success then
				warn(err)
			end
		end)
	end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.