Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to tell what kind of data is stored in a variable?

Asked by 2 years ago
local String = "Test String"
local Table = {1,2,3,4,5}

How would I determine which variable stores what kind of data? Does that question make sense, or do I need to clarify?

1 answer

Log in to vote
2
Answered by 2 years ago
Edited 2 years ago

Use the type() method! So basically,

local String = "Test String"
local Table = {1,2,3,4,5}

print(type(String)) --> "string"
print(type(Table)) -->"table"

It returns a string of the name of your variable's data type. So when comparing:

if type(String) == "string" then -- right

if type(String) == string then --wrong!
1
you can also use typeof(), which does the same thing but includes roblox objects. of course, type() is faster if you aren't checking roblox objects :) Speedmask 661 — 2y
Ad

Answer this question