User talk:Freefurbie

Lesson 1:Getting Started

Hello, everyone! I decided to make a scripting tutorial, because so many of you want to learn to script. Well, lets begin!

Starting Simple

Well, to start simple, we can make a kill script. We can start with this:

Make me die

well that is ok…I guess? NO! WRONG! HORRIBLY HORRIBLY WRONG! First, we need to define “me” and “die” is used by one of three ways: Setting health to 0 (read later lessons), Deleting your head/Torso. So, if you want to define yourself, you have to read on…hehe

Translating your script to Lua

Imagine that in the game, there is a folder titled “game”, and inside that is a folder titled “Workspace”, and inside THAT is a folder with your name on it! So you have game’s Workspace’s YOURNAMEHERE. Well, you can’t use the ” ’s ” in Lua scripting, so subsitute it for Mr. Dot. “.” So now it looks like this:

game.Workspace.YOURNAMEHERE

ya with me so far? Read the last few paragraphs over again to get the hang of it.

Adding The KILL In Your Script

To do this, you need to kill people one of two ways, you can either kill them by removing their head, or removing their torso. So that, in Lua, would look like this:

Head:Remove

or Torso:Remove

Let’s use Head Remove. Now our new script is this:

game.Workspace.YOURNAMEHERE.Head:Remove

YOU NEED CAPITALS! CAPITALS ARE SO IMPORTANT! ONE FALSE CAPITAL AND YOUR SCRIPT WON’T WORK!!! Now, lets test your Script! Go to My Script Builder and then type the following: create/killme (if killme is already taken, use something different, like bob) edit/killme Now type your script with YOUR NAME in the YOURNAMEHERE part. now say exit/ now say run/killme Your person’s head will pop off, and then you can substitute someone elses name for YOURNAMEHERE in a new script and you can kill them!

Lesson 2: Changing Values

In this lesson, we will change values! Those include health, transparency, etc. What is a value? A value is a number, 0, 1,000,000, etc. A value is displayed by the “=” sign.

Changing Health Values

You know that kill script we just made? Well, lets re-visit that, and we can re-do it, but this time, we don’t remove a body part, we change the health to 0. Well, that health is inside a Humanoid object, which is in your little “folder” with your name on it. So, lets take a look. Your script would look like this:

game.Workspace.YOURNAMEHERE.Humanoid.Health

Yay! Now here comes the changing values part. A value is displayed by the “=” sign. So, to change it, you would need the health to = 0. So now, your script looks like this:

game.Workspace.YOURNAMEHERE.Humanoid.Health = 0

Fun, right? Well, you can go back and test that at the script builder, but you need to remember to put your name in for YOURNAMEHERE, and you need to see this next lesson.

Changing Transparency

Time to change the transparency (visibility) of you Character! Well, as always we would start with your little “folder” setup:

game.Workspace.YOURNAMEHERE

Well, there is your setup…Lets make your head invisible! That would be displayed with that little equals dude again, and Head.Transparency = 1 So now, your script looks like this!

game.Workspace.YOURNAMEHERE.Head.Transparency = 1

HOORAY! TIME TO TEST IT IN THE SCRIPT BUILDER! Be sure to substitute your name/other people’s names for YOURNAMEHERE. Want something different than just completely visible and completely invisible? Use decimals! Use anything from 0.1 to 0.9!

Lesson 3: Wait Scripts

A wait script! What the heck is a wait script? Well, wait scripts are used like on blocks that flash between visible and invisible, they are using a wait function. The wait function is displayed with this: wait(INSERTNUMBERHERE) If you want to make your head flash between visible and invisible, you just need to add a wait function.Good thing you used that changing transparency lesson last time, you’re going to need it. Start with that and put it in the script:

making things flash between visible and invisible

game.Workspace.YOURNAMEHERE.Head.Transparency = 1

Time to add the wait function! This is really easy, all you need is this:

wait(3)

Why 3? Well that means 3 seconds. You can change it to anything you want. Time to make your head visible again!

game.Workspace.YOURNAMEHERE.Head.Transparency = 0

Now you just insert those as 3 different lines in the script builder, create a script for it, and run it! Your head will go invisible, then visible again! So now all together!

game.Workspace.YOURNAMEHERE.Head.Transparency = 1

wait(3)

game.Workspace.YOURNAMEHERE.Head.Transparency = 0

All the things that are values & Things to Remember:

All the things that are values are these: Transparency, Reflectance, elasticity, friction, etc.! Just mess around and have fun making scripts! Things to remember while using value scripts.

Lesson 4: Making Variables

Just what is a “variable”? It is something that defines part of your script and it is called a “Variable” because you can have the same name for something in a different script. Remember how you used to have to type this all the time?:

game.Workspace.YOURNAMEHERE

Well, what if I told you you didn’t have to! You could just type this!:

me

That’s it??!?! YEAH! Well, what you have to do is this:

me = game.Workspace.YOURNAMEHERE

Then, like in the kill script, all you have to type is this:

me = game.Workspace.YOURNAMEHERE

then press enter, and type in this:

me.Head:Remove

Saves a lot of typing time, right? Well, that is how you make a tag! If you want a tag for a Brick, name the brick something other than “Smooth Block Model”, like “Brick”. (no quotes and CAPS are required) Then you would define it like this:

brick = game.Workspace.Brick

Tags can be assigned to ANYTHING. You can assign a tag to your dog, if you want…but…Your dog isn’t going to play ROBLOX, so I wouldn’t suggest it.

That is a tag!!!

Lesson 5: Trues and Falses

What’s this? Trues and falses are the checks and un-checks in the properties box. You use these in a script with trues and falses. You can do many things like Anchoring and CanCollides. Lets make our first trues and falses script!

Changing Anchored Blocks to Un-Anchored

Here we go! Let’s use a tag from our last lesson. Our tag will be:

block = script.Parent

Now, we want to change the block to un-anchored! This looks like this:

block.Anchored = false

Now we can add a wait function

wait(4)

now we want to make the block anchored again!

block.Anchored = true

Now alllllll together!

block = script.Parent

block.Anchored = false

wait(4)

block.Anchored = true

Changing CanCollide

Just change the Anchored to CanCollide if you want a CanCollide Script.

block = script.Parent

block.CanCollide = false

wait(4)

block.CanCollide = true

CanCollide is the ability to walk through a brick and not walk through a brick.

Things to remember in a trues and falses script & all trues and falses

ALWAYS ALWAYS ALWAYS ALWAYS ALWAYS! Use LOWERCASE for trues and falses. ALWAYS TYPE TRUE AND FALSE IN LOWERCASE! ALWAYS! ALWAYS! ALWAYS! All trues and falses are these: Anchored, CanCollide, Locked, Archivable, ControllerFlagShown

Lesson 6: onTouch Scripts

Yes, yes, yes. Time for onTouch Scripts! These are the most common scripts in ROBLOX, but unfortunately, the hardest to learn. These are the 3 lines you are going to use THE MOST in ontouched scripts:

function onTouched(part)

end

and

script.Parent.Touched:connect(onTouched)

The Function

What the heck? What’s a function? Well I’ll tell you. The Function is what makes the script run. In this case, it is a touch.

Your first script

Lets create a wall that when you touch it, it becomes invisible and you can walk through it. Lets start by defining the wall with wall = script.Parent. You can use different things but script.Parent is the easiest for one object being defined. So after that we add the function. Since it is a wall, we use the hit function. Here it is so far:

wall = script.Parent

function onTouched(hit)

NOTE! Spacing and capitalization of are utmost importance!!! Now, lets use what we learned before so that we can change the CanCollide to off and transparency to 0.5. You probably already know this. But, there’s a catch. You must press TAB before each line in onTouch scripts. Don’t ask me why, I didn’t invent Lua. So here is what it looks like so far:

wall = script.Parent

function onTouched(hit)

wall.Transparency = 0.5

wall.CanCollide = false

Good! Time to add the wait function, so the wall will become solid again, and make it so the wall’s transparency = 0. Now we put it alllll together!!

wall = script.Parent

function onTouched(hit)

wall.Transparency = 0.5

wall.CanCollide = false

wait(3)

wall.Transparency = 0

wall.CanCollide = true

Kristomaster’s edit: Hey it’s just kris here that have changed the part after the wait(3) to wall instead of door, because naming it door will make it not work, just nice to help! =D

ALMOST DONE! You never had to add an end or a touch part to a script did you? That’s because they weren’t onTouch scripts. There MUST be an empty line between the end and the touch, otherwise your script won’t work. Now we do it alll together for the grand finale!

wall = script.Parent

function onTouched(hit)

wall.Transparency = 0.5

wall.CanCollide = false

wait(3)

wall.Transparency = 0

wall.CanCollide = true

end

script.Parent.Touched:connect(onTouched)

There is your first touching script! You can’t do it in my script builder, you have to test it at your place. Just put this script inside a wall in your place and it will work! Ta-daaaaaa!!!

EDIT: BY MYSELF. To use in my script builder/anaminus’, do this:

local s = Instance.new(”Script”)

s.Parent = game.Workspace.Base

s.Source = [[

wall = script.Parent

function onTouched(hit)

wall.Transparency = 0.5

wall.CanCollide = false

wait(3)

wall.Transparency = 0

wall.CanCollide = true

end

script.Parent.Touched:connect(onTouched)

]]

Lesson 7: findFirstChild(”Humanoid”)

What is findfirstChild(”Humanoid”)? Huh? What the heck…? This is all going to make sense soon. Ever seen a block that heals you when you touch it? How about a trampoline? These all use findFirstChild(”Humanoid”) I finally figured out how to do these. Now, we can talk about Trampolines in the next lesson about Vector3. (all explained later) a findfirstchild(”Humanoid”) is what targets everyone.

The new functions

Now, lets begin. We want to make a script that makes you get healed 100 percent when you touch it. Ok! Lets begin with the simple on touched function that everyone knows!

function onTouched(part)

Now this is where we add the 2 lines that make the script target everyone. Since this is a function, we will need to press the “tab” button, to make it so the script will run properly. These 2 lines are a new function that we will learn.

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

Meet The Locals

Kind of cheesy, huh? Yeah…well, a “local” is saying what a new letter, blah blah blah will be. You see local the most in Instance.new scripts. The sentence local h can be changed to anything like local shabalabadingdong. All you would have to do is change the if h~=nil to if shabalabadingdong~=nil then.

The Thens and the Nows

In the scripts, the line if h~=nil then translates to if h (meaning the humanoid, you) is in existence, (which you aren’t because you touched it) then do this: That is just a little explanation of how that works.

Okey dokey! Now let’s start the script:

The Script

Take the function lines and add them in a script like this:

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

Good! Now it is time to add the +100 health. The +100 health looks like this: h.Health = h.Health +100. We use “h” because “h” is everyone that touches the block. Since this is part of the new function, we need to press “Tab” AGAIN!

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

h.Health = h.Health +100

Now this is kind of confusing. We need 2 ends! 2?? Yes, because we have two functions. Now the script looks like this: (Don’t forget the ending connection!)

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

h.Health = h.Health +100

end

end

script.Parent.Touched:connect(onTouched)

Kristomaster says: If you guys wanna make the block deadly instead of healing, just change the +100 to -100 =D

Lesson 8: Vector3

YES! The sort of long awaited Vector3! Vector3 = 3 Vectors. The 3 Vectors are X,Y,Z. Vector3 includes: Position, Velocity, RotVelocity, and Size. Lets have some fun with Vector3! Let’s make a trampoline!

Starting off your first Vector3 Script!:

To start, we need our onTouched function so that the trampoline will activate when touched. We can’t make it hit, because hit is used for walls/doors/etc. So our function line is this:

function onTouched(part)

Now, lets make the Trampoline so that it affects everyone it touches. Now our script is this:

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

Where Vector3 Comes in

Good. This is where Vector3 comes in. In order to make your character fly up, we need to change the Y Vector. Also, the way to make your character fly up is Torso.Velocity. Torso velocity would look like this with our script:

h.Parent.Torso.Velocity

Now with the Vector3 your torso velocity looks like this: (the (0,0,0) will be edited later)

h.Torso.Velocity = Vector3.new(0,0,0)

Time to put that in! A good sized trampoline is 250-350 in the Y coordinate, so lets make it 300. Don’t forget the end connection! ~Ding

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

h.Parent.Torso.Velocity = Vector3.new(0,300,0)

Time to add our end functions. Very easy part! YAY!

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h~=nil then

h.Torso.Velocity = Vector3.new(0,300,0)

end

end

script.Parent.Touched:connect(onTouched)

CONGRATZ! YOU MADE YOUR FIRST WORKING VECTOR3 SCRIPT! Put this in any old block, and when you touch it, BOING! Goes your character!

Lesson 9: Instance.new

Whee! Time for Instance.new. To explain Instance.new, it is just creating something new. Like the black words across the bottom of the screen. That is called a “Hint”. You can make almost anything with Instance.new. Bricks are called “Part”, “Hint” is the black words across the screen, you can even make explosions! You can make anything that you can put in the Insert>Object box…

The Script

Here is a basic message script:

local message = Instance.new(”Message”)

message.Parent = game.Workspace

message.Text = “Blah blah blah”

wait(7)

message:Remove

end

Explaining it bit for bit

Lets begin by breaking the script down into little tiny bitty pieces that can be explained.

local message, local message? Well, that just means, that something called message is going to be whatever is after the = sign. Kind of confusing? Well, if you put it with this:

= Instance.new(”Message”)

It means, that something called message will be created into a new message. Make sense now?

message.Parent = game.Workspace the message’s parent can be anything, but it helps if you just make it game.Workspace. The text, does that REALLY need explaining? Um…NO! The text is what is going to be inside the message.

wait(7) We have done enough with wait to know what it means. All it means is wait(7) before something happens. What will happen is the message gets removed. If you want this message to repeat, do this:

while true do directly after the while true do, which means repeat, put a wait whatever to say how long you want it to wait before repeating. So if you want it to repeat every 5 minutes, your new script is this:

local message = Instance.new(”Message”)

while true do

wait(300)

message.Parent = game.Workspace

message.Text = “Blah blah blah”

wait(7)

message:Remove

end

CFrame (Finally Here!!!)

What the heck Is CFrame?? It is a Coordinate Frame, kind of like Vector3. This is explaining what CFrame is all about.

What the heck IS IT??

CFrame is like Vector3, but it moves anything welded to the block along with it, besides just plain moving one object. YAY!

How do I use it?

If you want to teleport yourself, but you don’t want to die, use this:

game.Workspace.yourname.Torso.CFrame = CFrame.new(0,0,0)

I always use 0,0,0 in scripts because you just need to put your own coordinates in there. If you want to give your torso a different frame, use CFrame! Why the torso? It is the main component of your ROBLOXIAN’S body. So, here is THAT script:

game.Workspace.yourname.CFrame = CFrame.new(0,0,0)       Ding says:YAY!

lookVector

Want to run FAST??? Now you can! With the lookVector function, it finds which way you are looking, and then it makes you run faster that way! Here is an example:

while true do — We want this because we always want you to run fast

wait(0.1) –We don’t want to wait to run fast, right?

game.Workspace.yourname.CFrame.lookVector * 60

Yah!! OH yeah! Now you can run super fast! I tried lookVector * 600 once in script builder…not a good choice. BOOM! Off the edge before you could say “Hi”. I’m not kidding!

Make your own functions

Now, many people think that you are stuck with these functions:

function onTouched(part) or (hit), function onPlayerEntered(newPlayer), blah blah blah. You know what I mean? Well, that is not true! Look at this perfectly working script: It works perfectly, and do you know why? I’ll tell you why!

function onOMGTheDoorHasBeenTouchedEveryoneScramble(hoobla)

hoobla.Parent.Torso.Transparency = 1

script.Parent.Transparency = 1

wait(5)

script.Parent.Transparency = 0

hoobla.Parent.Torso.Transparency = 0

end

script.Parent.Touched:connect(onOMGTheDoorHasBeenTouchedEveryoneScramble)

HOW THE HECK DOES THAT WORK?!?!?

Heh, heh…You see, it has NOTHING to do with the function. It is ALL ABOUT THE CONNECTION! You see, when you put this in a script:

script.Parent.Touched:connect(putfunctionNameHere)

you are essentially saying that when the script.Parent is touched, then the script happens. You put the :connect(putfunctionhere) to say what you are connecting the script to. Which is saying the function inside the parantheses. You can use your own functions for ANYTHING! This script can be turned into this:

function onPlayerEntered(newPlayer)

newPlayer.Torso.Transparency = 1

end

game.Players.ChildAdded:connect(onPlayerEntered)

THAT, can be turned into this:

function onSomeoneJoinedThisGameCelebrate(woohoo)

wait(5) –give player some time to exist

woohoo.Character.Torso.Transparency = 1

end

game.Players.ChildAdded:connect(onSomeoneJoinedThisGameCelebrate)

GetChildren

What…The…Heck? Why do I have an entire section devoted to GetChildren? Because, getChildren is VERY VERY VERY helpful! Have you ever wanted to change all of your character’s colors in a script but it was too long? How about an entire model’s CanCollide? You have lots of bricks so it is a P.A.I.N! Well, I’m here to solve that problem for you!

Starting Off

To start, you need something you want to happen. Let’s set an entire model’s brick’s CanCollides to false! Lets begin!

First off, we need a function for the beginning. (if you have a while true do or an onTouched, skip this part) Lets do this:

function blah

It does not need a property (thing inside the parantheses) because it is not a real function. You need one to start your script. So, here you go! Lets make it wait a minute before doing it.

wait(60)

Good! Now comes the GetChildren part. Replace MODELNAME with your model name.

p = game.Workspace.MODELNAME:GetChildren

You can use anything for “p” even shabalabadingdong! I use p, I don’t know why. It saves typing, that’s true. Now, we want it to effect the model, so here:

for i=1,#p do

that is targeting the “p” and then it means that the “i” means 1 part. So now, we only want the Brick cancollide off, not everything else. Now we sort them into bricks. A brick’s className is “Part”. Now, with the new thing, our script looks like this:

function blah

wait(60)

p = game.Workspace.MODELNAME:GetChildren

for i=1,#p do

if p[i].className == “Part” then

Good so far! Then, we want the CanCollide off, so we do this:

p[i].CanCollide = false

now, when it is all together, it looks like this!

function blah

wait(60)

p = game.Workspace.MODELNAME:GetChildren

for i=1,#p do

if p[i].className == “Part” then

p[i].CanCollide = false

end

end

end

STRINGS!!!!!!!!!!!!!!!!!!

Yes! The time has come for me to finally get off my lazy butt and write something semi-advanced for scripting for all of you that are like “Ugh! I wanna learn more but Dingdong272 is so lay-z he won’t add more!” Well, I am now! So, we’re going to learn all about strings! No strings attatched! Well, in this first lesson, there are.

Strings in a message

Have you ever been to an obstacle course, and when you win, it says this:

“YOUR NAME HERE HAS WON THE COURSE!”

Ever wonder how they do that? Well, I’ll tell you how! The trick is Mr. Dot times 2. The 2 dots string your name into the message! Cool, right?!? I know! This is how they do it:

function onTouched(part)

local h = part.Parent:findFirstChild(”Humanoid”)

if h ~= nil then

local m = Instance.new(”Message”)

m.Text = h.Parent.Name.. ” Has Won the Game!!!” –This line will be explained later

wait(3)

m.Parent = nil

end

end

script.Parent.Touched:connect(onTouched)

You’ll notice 2 new things in there.

1. The string attatching. Notice how there are two dots, space, “, space again (so the words don’t string togethere) and then the rest of the message and another “.

That’s the basic string format. Now, you can use multiple of them in one message, just so long as you remember these rules:

1.When the attatchment is coming BEFORE the message, the 2 dots come AFTER the attatchment. Like this:

h.Parent.Name.. ” Message”

2. When the attatchment is coming AFTER the message, the 2 dots come BEOFORE the attatchment, like so:

“Message ” ..h.Parent.Name

3.When the attatchment is in the MIDDLE, the 2 dots come before AND after the attatchment. Like so:

“Message ” ..h.Parent.Name.. ” Message”

Those are the rules. Now, you will notice the other thing, too. It is m.Parent = nil. Why does that work? Wouldn’t it remove the parent? No! Why not? Because, what you are doing is setting the messages parent to nothing, meaning it has nowhere to go. This is very useful, because you can do this:

local m = Instance.new(”Message”)

m.Text = “hahahahahah!”

m.Parent = game.Workspace

wait(3)

m.Parent = nil

–something else here

wait(1)

m.Parent = game.Workspace

m.Text = “hahahahha!”

wait(3)

m:Remove

see? Told you it was useful!

Now, more on strings will be coming later, such as string.lower and string.upper, as long as string.match and string.find.

- EDIT: Flamerider64 at April 2nd around 7:30pm GMT -

Yo! We’ve heard of this fancy new ClickDetector thingymabob that roblox added quite recently, but no newbie to scripting would know how it worked, but assuming you read all the way down here, you might be able to take a crack at it.

But first, let’s take a look at the actuall object itself and it’s properties.

Hmmm, looks like a normal object except for the MaxActivationDistance, this obviosuly speaks for itself. Adjust it to you’re liking, it could even be 100000 if you wanted. But how on earth does the darn thing do stuff when clicked? Well… let’s examine the lamp script:

————————————————————– local isOn = true function on isOn = true script.Parent.Bulb.Transparency = .5 script.Parent.Bulb.BrickColor = BrickColor.new(9) script.Parent.Bulb.Sparkles.Enabled = true script.Parent.Stand.BrickColor = BrickColor.new(24) end function off isOn = false script.Parent.Bulb.Transparency = 0 script.Parent.Bulb.BrickColor = BrickColor.new(104) script.Parent.Bulb.Sparkles.Enabled = false script.Parent.Stand.BrickColor = BrickColor.new(21) end function onClicked [!] if isOn == true then off else on end end script.Parent.Stand.ClickDetector.MouseClick:connect(onClicked) [!] on [!]

as much as all the red colours obstruct your view, think about how you could use this to do anything you wanted with ClickDetector. Ofcourse, take another good look, I’ve put beside the base lines needed for a ClickDetector script a [!] symbol.

Yup, just those three, I may have to go back and check, anyone can edit this just so you know. But here’s what it is in a normal script on it’s own…

function onClicked ’your function here’

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on

The ‘your function here’ line can be replaced by any scrip function of your choice, doing stuff that involves the person that clicked it may be a bit harder, but we’ll work off that.