Begin Scripting | Variable, Print/Warn

Hello Developers!

If you are trying to learn the basics of scripts, I hope this will help you!

NOTE: If you don’t know how to do the basics of Roblox Studio, you will not be able to do this tutorial, but you can learn that in my lesson: The Basics of Roblox Studio

Part One, How to Open a Script:

First:
Hover your mouse over “ServerScriptService”, and you will see a White “+” Sign pop up, press on the White “+” Sign.

After you press the White “+” Sign, you will see a menu pop up below “ServerScriptService”.

You will see 3 things in the menu, you want to press on “Script”.
image

Part Two, Print/Warn:

This is where the scripting starts!

Happy you have made it to Part Two!

After following Part One, you should see this on your screen:


This is where you will program!

Any time you make a script, you will see this code:

print("Hello world!")

What is Print:
Print is very useful in scripting, anything you put between the two parentheses, will be put in the “Output” window.

To show this working, go ahead and run the game by pressing “F5” on your keyboard, or press the Play Icon in the tool bar at the top of the screen:
image

After the game loads, when you look in the “Output”, you will see “Hello world!”:
image

Going back to the script (Press “Shift+F5”, or the Stop Icon in the tool bar), let’s make the Script print something other then “Hello World!”

print("Hello world!")

If you look at the script, you will see that the text that was printed, in in between parentheses, but in the parentheses, they are between double quotation marks (“Hello World!”) So, go ahead and edit the text between the 2 double quotation marks to what ever you want, I am going to change mine to “Scripting is cool!”

print("Scripting is cool!")

After editing it, go ahead and run it!

And when you run it, in the output you will see what you put between the 2 double quotation marks, be “printed”!
image

(Quick Tip: Double quotation marks ("–") and Single quotation marks (’–’) and both used to tell what is and is not a sting, anything you put between them, will become a string!)

Lets try something new! We have been printing, but now we are going to warn!

What is Warn:
Warn is the same as print, but instead of printing normal text, it prints yellow text as a warn-ing.

So how can we do it? It’s very simple, just replace “print” with “warn”

warn("Scripting is cool!")

And Run in!

When you look in the output, you will see the warn!
image
It works the same way as print, but will yellow text!

Part Three, Variables:

How you store values.

I am very happy you made it to Part Three!

Let’s talk about Variables!

What are Variables:
In scripting, they are used to store values like Strings, Numbers, and Objects.

How do you make a variable:
You use the word local, local mean local-variable (a variable that is only used inside of that script)

Format:

local VariableName = "Data"

After the work local, you put a space, then the same a the variable (the variable name must have no spaces, and must begin with a letter), and then you put a space and a equal sign and another space, then you put the data. (String, Number, and so on)

Variable Examples:

local Number = 10

local Name = "John"

local Where = "Work"

local Age = 27

How to use a Variable:

All you need to do is put the Variable name where you want that data, example:

local Text = "Scripting is cool!"

print(Text)

Now try it yourself:

Make a Variable of with you text:

local Text = "Scripting is cool!"

and then print the Variable using the VariableName:

print(Text)

Conclusion!

What you learned, and how you can keep learning!

In this Tutorial, you learned how to Print text with Print() and Warn(), and you learned how to make and use variables!

If you want to keep learning, keep trying new things, look stuff up that you want to learn (on Youtube, Devforums, but if you can’t find anything there, try google). and keep doing your best, you do not learn scripting in a few days, go slow, take it step by step, and in no time, you will be a great scripter!

If you have any questions or things I could have done differently, post then below, or contact be:

Discord: Dan_foodz#0751

Devforums: Dan_foodz

Roblox: Dan_foodz

Have a great day! - Dan_foodz, Developing on Roblox since 2020

6 Likes

You probably dont need to tell someone how to download roblox studio. its pretty unlikely that someone who hasnt actually knows the devforum exists.

1 Like

I just wanted to make sure, many people are going to be reading this, some know more then others.

tell them about string.format, very useful.

local cash = 50
local currency = "dollars"
local name = "John"

print(string.format("%s has %s %s!", name, cash, currency))
2 Likes

This is a beginner tutorial, if this is all they have seen, then if would be hard to go from what I have put here, to this.

(Also, I did not even know this was in roblox, I only know it from C and C++, LOL)

1 Like

i knew it from python at first then i figured this out

Just put it at the end, its not gonna harm

1 Like

I will make something else with this, thank you for posting :slight_smile:

It’s an example of Button Simulator’s Data but this is with the comments:

-- So first we will be making the stats..

local Data = game:GetService("DataStoreService"):GetDataStore("randomthingloldataxd") -- type somthing random in there

-- And check if player has joined the game

game.Players.PlayerAdded:Connect(function(plr)-- basically redirects you to the player here
	local s = Instance.new("Folder", plr)
	s.Name = "Stats" -- it will show ur cash n stuff in the leaderboard
	-- change if to stats if u want the cash to show on a gui (will show later how to make.)
	local cash = Instance.new("NumberValue",s) -- cash stat
	cash.Name = "Cash"
	cash.Value = 0
	local multi = Instance.new("NumberValue",s) -- multi stat
	multi.Name = "Multiplier"
	multi.Value = 1
	local reb = Instance.new("NumberValue",s) -- rebirth stat
	reb.Name = "Rebirth"
	reb.Value = 1

	local dataload = Data:GetAsync(tostring(plr.UserId))

	-- loading stats part

	if dataload then
		cash.Value = dataload[1]
		multi.Value = dataload[2]
		reb.Value = dataload[3]
	end

	while wait() do -- now the cash giver part
		cash.Value = cash.Value + (1*(multi.Value+0)) -- add *reb.Value if u want rebirths to multiply cash earnings
		print("The number of Cash is "..cash.Value)
		print("The number of Multiplier is "..multi.Value)
		print("The number of Rebirh is "..reb.Value)
	end
end)

-- now the saving part

game.Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(tostring(plr.UserId),{
		plr.Stats.Cash.Value, -- if you use leaderstats then do plr.leaderstats.Cash.Value
		plr.Stats.Multiplier.Value,
		plr.Stats.Rebirth.Value
	})
end)


-- now we are done with the data part, now lets make the buttons

Now, i will show you the Non-Commented one:

local Data = game:GetService("DataStoreService"):GetDataStore("randomthingloldataxd")

game.Players.PlayerAdded:Connect(function(plr)
	local s = Instance.new("Folder", plr)
	s.Name = "Stats"
	
	local cash = Instance.new("NumberValue",s)
	cash.Name = "Cash"
	cash.Value = 0
	local multi = Instance.new("NumberValue",s)
	multi.Name = "Multiplier"
	multi.Value = 1
	local reb = Instance.new("NumberValue",s)
	reb.Name = "Rebirth"
	reb.Value = 1

	local dataload = Data:GetAsync(tostring(plr.UserId))



	if dataload then
		cash.Value = dataload[1]
		multi.Value = dataload[2]
		reb.Value = dataload[3]
	end

	while wait() do
		cash.Value = cash.Value + (1*(multi.Value+0))
		print("The number of Cash is "..cash.Value)
		print("The number of Multiplier is "..multi.Value)
		print("The number of Rebirh is "..reb.Value)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(tostring(plr.UserId),{
		plr.Stats.Cash.Value,
		plr.Stats.Multiplier.Value,
		plr.Stats.Rebirth.Value
	})
end)
1 Like

ummmm, ok. thank you. This text will be blurred