[SOLVED] Argument 1 missing or nil - JSONDecode Error

  1. What do you want to achieve?
    I want to decode a raw string from a datastore

  2. What is the issue?
    An error (Argument 1 is missing or nil) is being thrown when passing in 1 argument (the string) so I’m guessing it’s the fact that it has no value…I’ve tried to fix it but I have no clue how to (I’m fairly new to JSON in Roblox)

  3. What solutions have you tried so far?
    I’ve tried to handle it using an if-statement checking if it’s just an empty string or nil. I used print() to print out the value of it, but it came out ‘nil’ while I have it checking for nil?

Players.PlayerAdded:Connect(function(Player)
	local function HandleNone()
		print("NO CHARACTERS FOUND")
		return
	end
	
	local CharacterValuesRawData = ""
	local CharacterValues = {}
	
	local Character1Values = {}
	local Character2Values = {}
	local Character3Values = {}
	
	local Success, ErrorMessage = pcall(function()
		CharacterValuesRawData = CharacterValuesDataStore:GetAsync(tostring(Player.UserId).."-CharacterValues")
	end)
	
	if not Success then
		warn(ErrorMessage)
		return
	end
	
	if CharacterValuesRawData == "" or nil then
		HandleNone()
	end
	
	print(CharacterValuesRawData)
	
	CharacterValues = HttpService:JSONDecode(CharacterValuesRawData)

You returned in another function, not in the main function.

local function Func2()
	print("doing some math")
	local x = 1
	local y = 1
	local oneplusone = 1+1
	return -- There is a return
end

local function Func1()
	print("Function 1 is running")
	Func2()
	print("it stops on the other function, not this function")
end

You should do this instead

if CharacterValuesRawData == "" or nil then
	print("NO CHARACTERS FOUND")
	return
end

But what if I want it to do nothing and return when that activates?

literally just replace the one use of HandleNone with a return and it should work.

I plan on using those two lines, and more inside of that function, later though.

I still got the same error. I replaced all of the lines and it still shows it.

Found the issue:

When I was checking if it was nil, I needed to check if CharacterValuesRawData was “” or nil, not just if it was generally nil.

Before:

if CharacterValuesRawData == "" or nil then

After:

if CharacterValuesRawData == "" or CharacterValuesRawData == nil then

I appreciate all responses though :slight_smile: