How to get Typeof string, correctly?

How do you check if a variable is a string? I can’t seem to get this to work.

local CheckString = function(userdata)
	local userdata = tostring(userdata) -- set "userdata" to a string
	if userdata == typeof(string) then
		print("String!")
	else
		print("Not string!")
	end
end
2 Likes

You would do

     if typeof(userdata) == "string" then
          --continue
      end
4 Likes
if userdata:IsA("StringValue") then
print("string!"
else
print("not string!")

if you wanted a quick explanation. userdata == typeof(string) will never be true because typeof(string) will return "table" as a string, but since i’m guessing tostring(userdata) in this case is never “table” then "table" ~= userdata

1 Like

The check you’re doing is redundant. CheckString will always print the true case, because tostring always returns a string, and you’re checking if tostring’s return was a string.

3 Likes