How can I structure an if statement that accounts for all three?

Code for the server side:

RequestAllOrSpecificAdditionalInfoRemoteFunction.OnServerInvoke = function(player, saveID)	
	
	local success, errorMessage = pcall(function() 
		AllAdditionalInfoData = dataStore:GetAsync(player.UserId .. "_AdditionalInfo") 
	end)

	if success and AllAdditionalInfoData then
		
		return AllAdditionalInfoData

	else

		warn("The Player has no Data!") 
		return false

	end
	
end

Code for the client side:
image

It either returns data, {} (the type is a table), or nil.

How can I structure an if statement (on the client side) that accounts for all three? Thanks!

What do you mean by “all three”?

All three of the possible things that the remote function returns.

Well, when you’re using an if statement doing: if variable then will respond the same if the variable is false or nil. So that covers all 3 bases. If the data is nil it’ll perform the else function, if the data is false it’ll perform the else function and if the data is a table it’ll perform the function in the if statement

So in this case, just do

if AllAdditionalInfoData then

else

end

image

image

image

image

How do I separate from {} and {...}?

he wants to check if its an empty dictionary too:

if next(AllAdditionalInfoData) == nil then or if you know one of the indexes you can do if AllAdditionalInfoData.value then

Oh I see you wanted {} and {…} in that case:

if AllAdditionalInfoData and next(AllAdditionalInfoData) then

else

end

wont work if its a dictionary:
image

Good point, he could just do if ~= {} then, updated my reply with this in mind

actually this won’t work bc {} creates a different table in memory than the original empty one

Yeah, rip; next(table) == nil seems to be the most optimal way to do it.

Updated the script I gave, thanks for your help bg9

yep, next() is the way to do it :D

I tried:

for _, _ in pairs() do
    -- code here
    break
end

but it didn’t quite sit right with me, so I decided to make a forum post. Thank you all so much!