I want to make sure what my datastore returns is a table and if it is anything else to just ignore it. Would :IsA work? If so I dont know how to make that work. I dont need you to write me any code. I just want to know an operator or something that would check. Thank you in advance.
✓ ANSWER ACCEPTED
How can I check to see if something is a table in my script?
1 answer
✓ Accepted answer
You can use an if statement like this:
local data = DataStore:GetAsync("key")
if not data then
data = {}
end
But you can also use the or operator instead
local data = DataStore:GetAsync("key") or {}
It will set the variable to {} if GetAsync() returns nil
Oh and if you want to check specifically for a table, use typeof()
local data = DataStore:GetAsync("key")
if typeof(data) ~= "table" then
return
end
1 comment
0
Thanks yeah I just want to check and see if it is a table. Not if its nil.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
type(thing) == "table"
Yeah I don't think posting an answer form is necessary on this one. What you're looking for is the built-in type function, as CJarmy mentioned. You can read more about it here: https://www.lua.org/pil/2.html
Thank you