Lua function: 'type', recreated in lua

Hello, I am currently recreating Lua Functions in Lua.
I have an GitHub with varies Lua Coding’s.
If you are making an Advanced Script, you may use my Script’s with Credit.
If you need help, my Discord is: johannesbuerger.

This Script works, but it can be better, this Script may be out of date. My GitHub will be always Up To Date: GitHub - OfficialValkyrie/Lua: Lua Scripts

--[[
Tested in:
Luau (Roblox)
Lua 5.2
Lua 5.3
Lua 5.4

Only the Current Checks will work.
Roblox Environment stuff will come later.
--]]

local proxy = {}
newproxy = newproxy or function(bool)
    if bool then
		setmetatable(proxy, {
			__index = {}
		})
	end
    return proxy
end

function CheckType(a)
	return ((a == nil) and "nil") or ((a == newproxy(true)) and "userdata") or (string.match(tostring(a), "^(.-):")) or (((a == true) and "boolean" or (a == false) and "boolean")) or (((tonumber(a) ~= nil and tostring(a) ~= nil) and "number")) or (((not tonumber(a)) and "string")) or ("Unknown")
end

function Function() end 
local Table = {}
local Thread = coroutine.create(Function)
local Userdata = newproxy and newproxy(true)
local Boolean = true
local Number = 1
local String = "Hello World!"

print(CheckType(Function)) -- Output: function

print(CheckType(Table)) -- Output: table

print(CheckType(Thread)) -- Output: thread

print(CheckType(Userdata)) -- Output: userdata

print(CheckType(Boolean)) -- Output: boolean

print(CheckType(Number)) -- Output: number

print(CheckType(String)) -- Output: string

If you wish, you may Improvise it and then give your Suggestions here for me to Correct.

I have already Updated it to Check if the given Value is an Instance. You may Check it in my GitHub now.

This won’t behave like Lua’s type global since you’re trying to tostring things, a userdata object can set a metamethod to change its stringified state (__type or __tostring). That would make your script not get a “userdata” string and consider it of the type “unknown”.

There isn’t a good way to know the true type of a data from Lua, without access to the VM itself.

I have already fixed some stuff, you may find it in my GitHub.

Oh yea, true. I also should make a normal check without using tostring, I will test some new stuff. I also merged a == nil with “Unknown”, so I could maybe make the checks that have no tostring first, afterwards some testing around. (The GitHub: Luau-Recreation/type.lua at main · OfficialValkyrie/Luau-Recreation · GitHub)

I am currently working on an way to make it check without the usage of tostring, it is a bit harder, but it is possible.