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

Why in script tho we ad a ‘ at the end and start of what string and why we use them?

I am having trouble with strings and I can’t figure out this script.

2 comments

0

Can you post the script?

0

You can use either ' or " to tell the script that you're making a string. Usually ' is for characters and " is for strings in other languages so I'd go by that rule.

2 answers

Hello!

We use ' and " at the beginning and end of strings to tell if it's a variable or a string. So it is used not to confuse the computer so they can know if it means string or something else.

An example:

local variable = "hello"

print("variable") --this will print the text 'variable' and not 'hello' since the quotation marks mean string and not getting the actual variable.

print(variable) --this will print 'hello' since there are no quotation marks so it gets the variable called variable instead.

Hope this helps.

Hello kind sir.

As described above in the other answer. Variables and strings are very cool. But the important thing to know is to put these tags "" between variables. The reason why you should do this is that the game can confuse strings with actual objects! let's see an example!

local string = "hello!"
local hello = nil

print("hello!")--This will print hello with no problems
print(string)--this will print a connected string. Use no tags because this is an ob
print(hello)--This will attempt to print a nil value, which is impossible because nil means nothing
--Therefore, this part will result in a script crash

Hope this helps you!

Best

TheLastHabanero

3 comments

0

-1 for "This will attempt to print an object from the workspace, which is impossible", and "Therefore, this part will result in a script crash". Do you know anything about metamethods?

0

Ok I changed it. You happy?

0

Dont be salty ok?

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