Comparing given time with required/accepted types?

Hi, is there a way I can get what type a varible is compared to what it should be?

For an example,

local function Test(Param1: boolean, Param2: number)
	print(typeof(Param1)) --> string - GivenType
	print(typeof2(Param1)) --> boolean - Accepted/required type

	print(typeof(Param1)) --> number - GivenType
	print(typeof2(Param1)) --> number - Accepted/required type
end

Test("Hello", 123)

I may be misunderstanding your question a little bit, but I believe that you should add the following line at the very top of the script:

--!strict

This will provide warnings / errors if the type given does not match what is expected.

Not what I need sorry, I need to be able to get the expected match because I want to compare the expected type('s) with the given type .

Luau is not a statically-typed language. Don’t waste your time enforcing it

Then no, you can’t get the type located in the params. You can always just add a variable within the function that says the expected type though.

local function example(var1: number)
	local var1Type = "number"

end

Other than that, there’s not really anything you can do

This is for an exploit prevention thing I’m working on so I kind of need it…

Thats sad as I needed it for an exploit prevention thing.

I doubt your game is so vulnerable that you need to verify types. At most, unexpected data would simply raise an error. If an error can take down some vital or protective system in your game, focus on making that system more robust

I guess thats true. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.