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

What is the difference between a string and a variable?

I do not understand the difference. They both seem the same to me, they both hold data.

1 comment

0

a string value has strings whereas a variable can hold strings, numbers, almost anything...

3 answers

✓ Accepted answer

They are a big difference. So, let me teach you about them.

Variables

Variables are things that can be used for later. So, instead of typing this

print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')
print('spam')

you could use variables!

local p = print
local s = 'spam'
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)
p(s)

Strings

Strings are basically text that you don't want roblox to run as actual code. For example, this would error

print(game.sometext)

because sometext is not a member of game. So, to tell the program "Hey, I don't want this code to run", we do

print('game.sometext')

Hope this helps!

1 comment

0

Also, you cannot hold terrain in a string.

First off, Here is a page I think you may find useful

A variable holds data that can be of any kind. A string is a kind of data that holds text. Other kinds of data are Integers(Number) and Boolean(Logic:True/False). So in other words, a variable can be a string but a string cannot be a variable

Variable

A variable is a name you can use to hold a value. In Lua, a variable can have any data type, such as a number or a string. See here

String

Strings are sequences of letters, numbers, and symbols. See here

1 comment

0

Your definition for string is not helpful.

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