Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make "if" for string value? How to release this script, to work it?

I want this:

local randomString = "Random"

if randomString = **string** then
print("Its a string!")
else
print("Its isn't a string!")
end

But how to release this script, to work it?

2 answers

✓ Accepted answer

Use type. Type will return table, string, number, boolean, or userdata if it's one. local randomString = "Random" if type(randomString) == "string" then print("Its a string!") else print("Its isn't a string!") end

4 comments

0

What I need!

0

Shouldn't type(randomString) = "string" be type(randomString) == "string" ?

0

^

0

Yes, common error lol

Using type() will help you here! Here's some code I put through lua and the results to help you out:

local f = 1
local sa = "1"
print(type("fsa"))
print(type(f..sa))
print(type(f))
print(type(sa))
print(type(function() print("foobar") end))

Output:

string
string
number
string
function

For example:

if(type("string") == "string") then
print("foo")
else
print("bar")
end

Output:

foo

If you need any help just ask! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.