If i have a variable that is assigned to a player instance, how can i check what type is that variable and apply a check so if variable…type. == “PlayerInstance” then… print(“it’s a player!”) end?
and also is there way to check what class type a variable is, for example a folder?
Use the instance’s .ClassName property to find what it is if you don’t know what it is, however you can use the instance’s :IsA method to find whether something is an instance or inherits an abstract class (BasePart, GuiBase, GuiObject, ValueBase etc).
If i have a variable that is assigned to a player instance, how can i check what type is that variable and apply a check so if variable…type. == “PlayerInstance” then… print(“it’s a player!”) end?
You can use the type function:
local Test = game.Players.LocalPlayer
print(type(Test)) -- userdata
Example in a if statement:
local Test = game.Players.LocalPlayer
if type(Test) == 'userdata' then
print(Test)
end
More information on type and typeof:
and also is there way to check what class type a variable is, for example a folder?
Check the answer above.
Keep in mind that is just an example.
The main difference with type is that it is also used in vanilla lua, typeof is a Roblox function.
You can use the built-in functions typeof() and type() to check the types of values. To use them simply pass the literal value itself as an argument to either function or pass the variable of which is being used to store the value, for example:
type("Hello") --would result in the type string
type(1) --would result in the type integer/number
local function hi()
return
type(hi) --would result in the the type function