Beginner's Roblox Scripting Tutorial #8 - If Statements (Beginner to Pro 2019)
Вставка
- Опубліковано 18 жов 2024
- Beginner's Roblox Scripting Tutorial #8 - If Statements (Beginner to Pro 2019)
Hey guys, in today's video I am going to be teaching you about if statements. Now these are very important because you will use these all the time when you are scripting and they are useful for finding out values of variables. If statements are pretty easy though so no need to worry. As always if you have any questions be sure to leave a comment, and I will get back to you as soon as I can! I hope you guys enjoy the video and I'll see you tomorrow!
Link to Beginner's Tutorial Series:
• Beginner's Roblox Scri...
-- Follow me on twitter! (my name is tapwater because thats my main channel): / realtapwater
- Join my Discord Server to learn and meet other developers!-
/ discord
--What is this series about and who is it for?
So this series is meant for people who really want to learn exactly how to script, if that is you then I promise by the time you watch this whole series you will know exactly how to script on roblox. Anyways be sure to subscribe to see whenever I release a new tutorial and I will see you guys in the next one. Peace!
Hey guys! Be sure to join the discord server if you have any questions or if you would like to meet me! discord.gg/FKcSyRh
i was trying to hack to get free robux. now i am making a game so thx for your help
so if i do this script it should give me the trancperacy of my baseplate?
if Baseplate == 1
print ("Yes")
end
would it work bcs imma try it
lol ik you dont see this anymore but THAT WAS AWESOME
@@saidabdiche5890 roblox mods I n t r e s t i n g ...
@@EuphoricPlaceHolder im sorry it wouldent ik im not dev but you should type this i belive i could be wrong local Baseplate = game.Wokspace.Baseplate
if Baseplate.Transparency == 0 then
game.Workspace.Baseplate.Transpareny = 1 I belive this last part is wrong but hey im not an expert it may work
If statements are by far one of the most fun things to play around with in scripting. The amount of power an if statement gives you is just unmatched
ikr lmao
@@GoofySillyGuy samee
yes, then i wanna mess around with statements and random
Are you allowed to use != < > and all those in lua aswell?
@@col2650 yes, but the ! symbol is quite complex
1:00 for my people learning to script on roblox during quarantine, the simpler understanding is that == is asking "are they equal?" and = is saying "this is the value
Example: 3 == 3 it's checking if the first value is equal to the second value
x = 3 its saying that the value of x is 3
What this means?
if variable then
--code
end
if variable what
@@LegoPieces_
@@LegoPieces_ end is a function which is used in script ends and sometimes used in the middle of a script or anywhere they are a function which makes the script stop and
Example : so when your script is got red line under for no reason the end is used if 2 are red lined it will be
end
end)
@@LegoPieces_ Variables are a function which holdes all the data of the script
Examples: if your script is in a part in workspace you need to write
local (partname) = script.workspace
If you want to make a script a child of the part or item you need to write
local (where your inserting the script) = script.parent
this makes the script a child of the item or part your inserting the script
@@LegoPieces_the word code dosent exist in lua...(Maybe)
They are used in printing tho
I was terrified to start scripting but once you get going you notice some patterns. Thanks for this series it's helped a lot
True right?
Watching this in 2024, still the most easiest to understand tutorials out there
AlvinBlox is a good option too! but this one def better
@@rowlzz idk Alvinblox is just confusing
true
I like this channel
+1
All though its been 5 years i am now a pro scripter cause of this guy and he does such a fantastic job of explaining scripting and all that stuff and without him idk if i would of been able to script lmao
Im happy for you bro I just started 1 day ago and I hope to get better
This one is easy. Love it man keep it up!
Thanks bro :))
Please make more I really want to learn the full steps.
@@TheDevKing hey bro do you have any successful games that you have made and hoe much robux have you made from them?
@@Oiluptylervitelliorelse5 years ago he made this, I don’t think he is gonna still comment on a video from 5 years ago.
Your tutorials are so helpful and easy to follow, I love the content man! I haven’t found any others that have made it this fun and easy to do.
Thanks man! Glad you enjoy :)
couldn't have agreed more
That is right
so relatebele
@@TheDevKing live long life
The fact that you're tutorials are also kid friendly just makes it better so aspiring developers on the younger side can also learn
Just like me lol
Yeh lol I’m 10
Why are there kids here now
@@Sejdkkk They want robux
POV: Me, who is 10, trying to learn scripting so that I can make games:
I love how this man explains things, it's helping me learn the basics so quick
Definitely
Just now going through your tutorials and they're super helpful! I really like that you give a lot of examples when explaining it bc it makes it easier to understand :)
Thats awesome! I'm glad It could help. You'll be at the advanced series in no time :)
2nd Comment lol
Thanks to this series i managed to make my first script !😁
local Baseplate = game.Workspace.Baseplate
local function Test()
Baseplate.Anchored = false
wait(2)
if Baseplate.Anchored ==false then Baseplate.Anchored = true
end
end
Test()
local Baseplate = game.Workspace.Baseplate
local function test()
if Baseplate.Anchored == true then
Baseplate.Anchored = false
wait(2)
Baseplate.Anchored = true
end
end
test()
It should be more like that
i’m bad at scripting but you could make it even shorter maybe idk
local base = game.Workspace.Baseplate
base.Unanchored = true
wait(2)
base.Anchored = true
keep in mind that i wrote this with only 20 minutes of tutorial watching experience, expect it to not work at all 👍
@@ehtz It would work but only once but if you put it in a function you could call on it to do whatever you want just by putting as what he put Test() Which you can make repeat by doing,
While true do
Test()
end
Hope this helped!
@@noobsarebetterthanu5820 well im a noob
Nice
I love this, you are the only tutorial i could find that is not hard to understand, definitely making a game by the end of this!!!! Love this series!
Me too
me too
Cosmic Blox hey guys wanna share some ideas to each other and probably help each other out add me on discord Riryo#1652
pelumi bello Cosmic Blox hey guys wanna share some ideas to each other and probably help each other out add me on discord Riryo#1652
@@RealSpyduh can u build?
Honestly, this is one of the most self explanatory tutorials here...aside from the having == instead of = to avoid confusion with the variable things
== is used in every type of programming im sure
he has managed to fit this topic into a 7-minute video while all those Roblox scripting "pros" make a whole 20-minute video and in the end, you barely understand a thing they said. Your content is very beginner-friendly, keep it up and never give up!
All these years I knew you, I never knew you were so talented at stuff like this.
Thank you for the tutorials, they help me a lot!
Keep up the great work!
same
These tutorials are very helpful! I've been doing scripting for a while and I am not fully advanced. These things help set me up for certain things. Thanks so much for making these series.
I like if statements, and I'm excited to learn them! I've been wanting to learn them for a long time! Cool!
Me too!
the if statements have a big importance to me, i am very sure many other fellow developers think these statements are important and they can’t make their games without them.
me too.
@@firacita mhm! Like if you want to do:
if - line of code right her then
print(“”)
If statements are really important.
Uhhh... What us if statements really for?
I have watched so many coding tutorials and they all make it super complicated. Thank you so much for this series. I am confident I will be able to make a game by the end :)
He doesnt explain best practices. Variable names need to be descriptive.
Don’t know why but a year ago I struggled really hard with these, they were way too complex for some reason and my brain couldn’t learn it right. It almost led me to copying code, but I just decided to stop Roblox developing in case I did start to copy Roblox code. But a year later and I decide to look back into it, and I can understand this tutorial so well and I even took some notes that helps me even more. Thanks DevKing 👍! Not that prepared for advanced but I’m ready for anything 😃
hve to take notes?
@@tkn1ght493 i always take notes its fun
Yo devking I was very confused with scripting and i thought i couldnt do it. But when I found you in UA-cam, it helped me learn alot! Thanks devking❤
man ur the best i still cant belive that i understand this now instaid of thinking those are random words and "what the heck do they even do" i dont have that feeling after watching ur playlist
*first 25 sec* explains the concept I didn't understand for 2 days
me: yeah this is the good tutorial
Ikr
if statements are actually so easy if u got experience
Thanks for these tutorials man, really nice and well explained. I'll be sure to like these videos, and re-watch them.
2022 and this guy is still giving the most usefull lessons, tysm gonna see the entire thing again so i can understand
im kinda late to your beginners roblox scripting series but 3 mins into the video i already knew what if statements are so thankyou and ill be sure to be a pro soon from your videos :)
Using this tutorial I made an if statement to check if the baseplate was anchored, if it wasn’t it said “Anchoring the baseplate...” I then used code to anchor the base plate and then printed “The baseplate has been anchored”
Cool! I made some code that makes the baseplate dissapear smoothly. Here's the code. [plez credit me waa]
local PartTransparency -- The Baseplate's transparency, if it wasn't obvious enough
local i = 0 -- For a loop
local Baseplate = game.Workspace.Baseplate -- I know this isn't needed but it's to make my code shorter
Baseplate.CanCollide = 1
wait(10) -- Initialize collisions, just in case
while i < 1.1 do -- Basically how this works is "while" a condition is true [or yes], it will do this action. Otherwise, it stops.
i = i + 0.1
PartTransparency = i
Baseplate.Transparency = PartTransparency
print(i) -- For debugging. I have no idea why the decimal points go from 0.2 to 0.399999999999999. Floating point is very smart
if i > 1 then
Baseplate.CanCollide = false
print("Oh teh noes! Da baesplate haz DISSAPEARED!") -- For fun. Don't re-correct the message, otherwise you're a huge nerd.
end
wait(0.01) -- For any silly classic C++ bards, yes, they measure waiting time in seconds, not milliseconds.
end
@@bearreyes1837 You can use tweening, its good piece of code. Tweening is so smooth and very easy to learn
@@its_hallux4581 I actually know already, I just didn’t discover it that time I made the code.
Hey, thank you so much! I know it's not much, but I must thank you for teaching me! I was able to write a function that made a part become red, Neon and then into a ball after your if statement video. Keep it up! Also, I think I saw a huge bost in confidence her!
Im a few months into scripting. Watching through the playlist for beginners to refresh! This one caught my attention pretty awesome if statement tutorial!
i dont like how he explains one thing for too long
but i like how he goes straight to the point
Don’t worry, I usually say “equals equals”
gamerdude4 lel
Ok
* Equals to equals to
lol
I just say it as "if it equals" because that's what it means.
Gotta love the like to dislike ratio, 1.1k likes and only 9 dislikes. Proves how good your tutorials are.
This is an AMAZING tutorial series
i had a little fun and did this,
local x = 1
local y = 3
print (x+y)
if x+y==4 then
print ("yes")
end
i made it so it says "yes" when 1+3=4
which it is so the output is
4
yes
Yeah I taught myself some scripting basics
just wait until you learn about elif, you can make it say "no" if 1+3 is not 4!
This one is one of my favourite. Your tutorials are very nice and fun. Keep it up!
hey man. ive never scripted but im here on the 7th tutorial and i really understand and im starting to script alone. i used to think how people just make the scripts out of their mind. now i do it! thanks for these videos.
really good i took a break and i started watching over again it was so good that i remember almost everything!
this video is the best tutorial I have ever seen because I now know how to make a "if" statement and "if" statements are so important in scripting. thank you TheDevKing
Hey even after 5 years its still pretty nice!
I learned much things from you thanks man!
What i learned for if statements:
local part = game.workspace.Part
if part.Anchored == true then
part.Anchored = false
wait(1)
part.Anchored = true
then can be done with numbers too:
local x = 3
if x == 3 then
print("Yeah boy")
This will print ("Yeah Boy") because x = 3.
If statements
Local x = 3
If x == 3 then
Print (“yes”)
end
- When making an if statement two equal signs are needed to check if it's equal.
We use if statements to find things out so if a player has 1000 dollars then they can buy this item
Local x = 3
Local x = 4
If x == 3 and y = 4 then
Print (“yes”)
end
--The and lets you add more things so let's imagine a player needs 1000 dollars and 2000 exp to get this item
Obviously if you don't have one or the other you can't get the item
P.S thank you devking for these tutorials they are very helpful
these tutorials are actually so good lol :) and it feels entertaining lol
I love the way you explane the scripting and now my best script is
local Transparency = 0.5
local Anchored = true
if Transparency == 0.5 and Anchored == true then
game.Workspace.Baseplate.Transparency = 0.5
game.Workspace.Part.Anchored = false
end
print ("it worked!!!")
i made a discovery if you put local x = 7
local y = 2
if x or y == 9 then
print ("YES")
it will print YES because it adds up and idk if he covers it later in the playlist but this is for people who didnt know
THATS THE MOST EXPLAINED AND BASIC THING YOU EXPLAINED ME, here is a script that makes the baseplate invincible after 3 seconds:
local Cheese = true
if Cheese == true then
wait(3)
game.Workspace.Baseplate.Transparency = 1
end
if you want to make it even more complex then you can do
local a = game.Workspace.Baseplate
if a.Anchored == true then
a.Anchored = false
end
wait(2)
if a.Anchored == false then
a.Anchored = true
end
Thank you I really appreciate your hard work to teach us all scripting and I did learn scripting from you and I'm really great at it now, so I started teaching other people how to script, thanks man we all really appreciate your teaching and hard work :)
THANK YOU SO MUCH! ive been trying to learn lua but i really didnt know where to starts from. I watched Up to this video at the time of this comment and i managed to make a colorchanging part!
thank you so much dude. these tutorials have helped me so much, and i'm doing a lot better at scripting
bro that makes me have an idea for a generator from a horror game, im so excited for learning more!!!
Im going to put my code here for anybody who didnt understand it,
--My Code
local x = 3
local y = 6
local z = x+y --variable adding x and y
if z == 9 then --If z equals 9 then print 69 to the output
print(69)
end --The end
--If You didnt understand the video, try editing this code in roblox studio :)
one of the commons examples of If statements will be Players Health:
local playerHealth = 50
if playerHealth
You ain’t joking about being the dev king being a good king, helping your people!
While watching this I got kind of a grasp on elseif statements, so thank you again TDK :D
just an explination for someone who doesn't know yet
The "=" operator is the assignment operator, which is used to assign a value to a variable
Example
X = 10
The "==" operator is the equality operator, which is used to compare two values for equality. It returns true if the values are equal and false otherwise
x = 10
if x == 10 then
print("x is 10")
else
print("x is not 10")
end
In short " = " is to give a value for or to that variable
And " == " is to check the value that it is given
Fun thing about lua and python is that even if you learn 1 you can also easily master and learn another
I learnt puthon and because of that lua is every easy
same
Local x = “Dababy”
If x == “Dababy” then
Print(“Less go”)
end
@@roguenogue local x = Dababy
if x == Dababy then
print("less gooo")
end
local x = "less go"
if x == "Dababy" then
print("converteble")
elif x == " crewmate " then
print("susbro")
else
print("joemama"
end
@@unsimplehumain116 elif - elseif ?
print(“joemama” = print(“joemama”) ?
@@ItsLeeeroy ya im typing fast but elif is a real thing
mobile user detected initiating femur breaker
Yay! I was excited for this one, always wanted to learn about if statements.
For who still doesent get it it's simple it's just like if this block is anchored then play that music or something, and for who doesent understand wait you just put wait(any number) and the number you put next to wait is how many seconds it will wait and after the seconds finishing you have to put a script after the wait and it will play the script after waiting
Thank, you dude!! I’ve learned a lot about scripting bc of you!
His short chuckles makes the tutorial more lively tbh
Knowing python definitely helps! Thanks for the videos!
I totally agree I recently started learning Python and Java and I realized lua is like both those languages
In 1 day ican see 8 videos and it’s very good and thanks for learning
I watched a tutorial at my language he of course teached if then else if but he didnt even teach “And” iam so glad i know you and watch you
Im watching much after the vid was made but tbh this guy is literally one of the best teachers
im learning stuff already 1:15 into the video because i already understand it because its like a function, im learning stuff and im proud. i put this code into the script:
local function hi()
print("Hotdog")
end
local x = 3
if 3 == 3 then
hi()
end
and it worked!!!
This guy is an absolute legend
This tutorial was so teaching because of everything man
Best part about learning to script is feeling smart when it acctualy works
only 7 minutes? im subscribing
your really helpful, got a new sub! thank you sooo much for your scripting tutorials!
my parents put me in a course to learn coding. out of all my 5 months(I think), I have learned more from here
I learn from here only because I really want to make Roblox games :)
Really equal to :-) I like that wait function you called there, that is going to be used all the time for events I would assume?
this is soooo coool most coolest scripting tutorial i have ever seen
ok so basically for those who doesnt get if statements lemme explain
if statements are basically used for like example
**local guy = true
if guy == true then
print("Guy is true")
end
if guy == false then
print("Guy is false")
end**
4:51 the most satisfacing sound in this vid
5:22 u can also replace
If Baseplase.anchored
By using the variable:
If Baseplate == true
BUT you will have edit the variable to this:
Local Baseplate = game.workspace.Baseplate.Anchored
You're tutorials are easy to understand and helped me script thank you
gotta be my favourite part of the code because its so intuitive and easy to understand lol.
just found out something, if you higlight some text in RBX studio and do a parenthesis it will do a parenthesis around the text :0
learned one thing i didn't know about if statement thx bro
Thanks for ur vids they really help me :D!
For those who don’t know, “Wait()” is an outdated version. Yes, it still works but to ensure smoother code execution do “task.wait()”
Keep up the great work, you taught me 98% of the scripting I know
this helps me alot thanks devking
For anyone watching, you could use If statements to fix bugs in your game. For example, you could have it detects if a player has glitched into a area they shouldn't have, if they have then it teleports them out of there.
How? I mean I understand this. But how do you type it?
@@AriusWight man I typed this 9 months ago I’m onto. Better things lmao.
you can ask this on the dev forum though
@@AriusWight were not in advanced so I don't exactly know but I bet it's like: you need a part, name it "OutOfBounds" and make it transparent and to have collideable false but cantouch on, then make it so when you touch "OutOfBounds" it teleports you to a in bounds coordinate and boom.
I am subscribing. This is the best youtube channel
You explained this sooo well. Thanks a ton man :D
This guy deserves a sub
local ground = game.Workspace.Baseplate
ground.Material = "Marble"
ground.Transparency = 0.6
local function add(player, friend)
print(player + friend)
end
add(3, 5)
local x = 3
local y = 6
if x == 3 and y == 6 then
ground.Anchored = false
end
what i've put together so far
Really great tutorial thanks for the tip at the end.
Absolutely amazing work!! now i can make my objects unanchred and stuff!!
tutorials still work well thanks so much man!!
I think that if statements is the coolest part in scripting.
Dude switch statements are the cooler if statement
they look so nice, as well
switch(value){
case 1: std::cout
Thanks man you really made me learn functions
Simple and easy to learn. Thank you so much bro!
just saw this video and i managed to do this!!!
local baseplate = game.Workspace.Part
if baseplate.Anchored == true then
print("yes mfer its anchored and ima unancher hehe")
wait(2)
baseplate.Anchored = false
end
wait(4)if baseplate.Anchored ==false then
print("chill imma make it anchored again")
baseplate.Anchored = true
end
im so happy that it worked ty bro
thx im now able to make plugin that won't actually really work but there is example local function Test1()
local game workspace.Part.Transparency = 0.5
if 0.5 == 0.5 then
print("Hacker")
end
end
Test1()
thanks for your splendid tutorials that will help me achieve my dream to become scripting enthusiast.
That's really nice, but you could kick them (or ban them) if you replaced the print with this.
local player = game:GetService("Players").LocalPlayer
player:Kick("Kicked for Exploiting!")
----------------------------------------------------------------------------------------------
I don't know if this will work though.
just a silly little combination i made.
local Baseplate = game.Workspace.Baseplate
if Baseplate.Anchored == true then
game.Workspace.Baseplate.Transparency = 1
end
this makes so the baseplate only can change its transparency when its Anchored.
Dude, you just got the Oscar for being so epic.
Love the vids so far, i really can come along pretty good.
Thank you.
- Drago
I love you man you made my day thank you. love it ❤️