Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --By Anthony--
- Scripting help for myself and others.
- I will be covering basics which allow me to learn from them and refer to.
- Parents -
- A parent is any object in the game. Workspace is the most often used parent which holds the character
- and the bricks that you see.
- The Workspace's Parent is game. Example --> game.Workspace.Player1 <-- This finds Player1's Character and goes
- through its parents which is --> game.Workspace <-- which is basically its location.
- Visual Explanation ---> https://gyazo.com/e7d9de20567cd5451564a207cfbf1985 <--- game.Workspace.Baseplate is the
- location of the Baseplate.
- Things to remember about Parents. "game" not "Game"
- "Workspace" not "workspace"
- Remember to seperate with .
- ------------------------------------------------------------------------------------------------------------
- Using Instances -
- Instances are how someone inserts something into the game without manually inserting it. Scripters choose to
- insert things like Values and Parts by using a script. The way this is done is by typing "Instance.new" inside
- of your script. (Without the "") This tells the script that im about to create something from advanced models.
- You will need to put the name exactly how it is because they are case sensitive.
- So now we know that Instance.New is how to create something, we can specify what we want,
- for example Instance.new("Part") this code would create a part, but it wouldnt be visible because it has no parent.
- So we give it a parent by putting Instance.new("Part"),game.Workspace) This tells it to put the part into
- game.Workspace where bricks are visibly seen by players.
- Visual representation - --> https://gyazo.com/841c33311c196f0b0b857102c3b039b2 <--
- Things to remember about Instances. Ensure the i in Instance is capitalised
- Ensure the n in new is lowercase
- Ensure the item im inserting is case sensitive
- ------------------------------------------------------------------------------------------------------------
- Configuring Properties -
- A property is just settings of an advanced object. So for instance, you have properties known as position,
- transparency, size, name and more. So we will work with transparency and reflectance then move on to naming
- and strings.
- So lets begin by inserting a brick into Workspace, like the picture shows in frame one. So inside the script type
- the parent of the brick (game.Workspace.Part) then follow by adding .Transparency =.5 so it will be
- game.Workspace.Part.Transparency = .5 this will make the object known as "Part" 50% visible. The same process
- works with reflectance. game.Workspace.Part.Reflectance = .5 .
- Things to note - If i have multiple objects named part, it will choose one at random.
- Chaging the material property is a little harder. "Material property" is game.Workspace.Part followed by .Material.
- So it will be game.Workspace.Part.Material. Once ive done that, i can give it a material. E.g. "Grass".
- So it will be "game.Workspace.Part.Material = "Grass" This tells the script that i want the material to be grass.
- Other materials consist of the official materials e.g Slate, Sand, Wood, Foil, Metal etc.
- ------------------------------------------------------------------------------------------------------------
- Destroying and Removing -
- Remove is a commonly used command to delete an object permanently as destroy makes its parent nil (Has no parent)
- which means that both of them remove the object.To remove an object, you locate its parent and follow it by typing
- :remove() or :Destroy(). This removes or destroys the object. Example: game.Workspace.Model:remove() <-- Removes
- the model. game.Workspace.Model:Destroy() <-- Destroys the model.
- ------------------------------------------------------------------------------------------------------------
- Learning the Output -
- The output is the scripters best friend, it displays all types of problems with the game and things that are possibly
- wrong with the script. It can also help you test things to see if any part of the script errors.
- Setting it up: Open Studio > View > Output
- Many scripters use print to find errors in their scripts, in a script, the word print is just an option to put text
- in the output. So if i type print("Chocolate") it would appear in the output as the word "Chocolate". You can use
- print to do mathmatic calculations and to test if your scripts are working, also to debug.
- Visual Example - https://gyazo.com/1147b1cec892242e870420e08fb9b9c4
- ------------------------------------------------------------------------------------------------------------
- Using and creating variables -
- A variable is a holder, it holds data. Just like a storage, a variable can be many things. We create a variable by
- typing VariableName = . VariableName can be anything. So try HelloWorld as the variable. In variables, you can
- hold strings, numbers, parents, and all kinds of things. Lets say for instance we wanted to hold a number,
- we would type
- Number:
- HelloWorld = 5
- Parent:
- HelloWorld = game.Workspace
- String:
- HelloWorld = "I love Cookies!"
- ------------------------------------------------------------------------------------------------------------
- Working with Bool Values -
- A bool value is a simple true or false, for instance, lets use Anchored as an example. Anchored uses true or false
- to choose whether it is or isnt. Example:
- Instance.new("Part",game.Workspace) <--- This tells the game to create a part in Workspace
- game.Workspace.Part.Anchored = true <--- This tells the game to anchor that said part.
- This would make the brick anchor itself, same goes with CanCollide
- Instance.new("Part",game.Workspace) <--- This tells the game to create a part in Workspace
- game.Workspace.Part.CanCollide = true <--- This tells the game to make the part CanCollide
- A bool value can be used for endless possibilities.
- ------------------------------------------------------------------------------------------------------------
- Editing Lighting -
- GlobalShadows and Outlines are properties that use the bool value, to configure these you would type
- game.Lighting.GlobalShadows = false <-- Disables GlobalShadows
- game.Lighting.Outlines = false <-- Disables Outlines
- You can also configure the brightness by typing
- game.Lighting.brightness = 2 <--- This is the brightness of the game
- Another simple property that is easily edited is FogEnd or FogStart
- game.Lighting.FogEnd = 1234
- game.Lighting.FogStart = 4321
- ------------------------------------------------------------------------------------------------------------
- Adding a Wait Value -
- A wait is used to control the script on a timed basis. For instance, you can make a script that creates
- a brick, changes its transparency to .5 after 3 seconds, then deletes itself after another three seconds.
- To do this, youd type
- Instance.new("Part",game.Workspace) <-- This creates the part
- wait(3) <-- This tells the script to wait for 3 seconds
- game.Workspace.Part.Transparency = .5 <-- This changes the transparency to 0.5
- wait(3) <-- This tells the script to wait for 3 seconds
- game.Workspace.Part:Destroy() <-- This destroys the part
- This would create a brick, make its transparency .5 after a 3 second delay, and then remove it after another
- 3 seconds. Wait must be "wait" as lowercase otherwise it will error. Instead of "Wait" you put "wait".
- Wait - Wrong
- wait - right.
- You can use waits for VIP doors, guis, messages and much, much more.
- ------------------------------------------------------------------------------------------------------------
- Editing an Instance -
- Editing an instance isnt much different from creating one. The way to do this is simply by adding one little
- bit of coding. So lets say we want to create a part and anchor it, we would type
- Instance.new("Part",game.Workspace) And then follow it with .Anchored = true
- Full code
- Instance.new("Part",game.Workspace).Anchored = true <-- Creates a part and anchors it
- This will anchor the part as if it was
- game.Workspace.Part.Anchored = true <-- This way also works
- You can also do things like
- Instance.new("Part",game.Workspace).Transparency = .5
- Or
- game.Workspace.Part.Transparency = .5
- Also you can do
- Instance.new("Part",game.Workspace).Name = "Brick" <-- This creates a brick and renames it
- ------------------------------------------------------------------------------------------------------------
- Kicking a player -
- Kicking a player isnt hard at all, you can possibly even create your own admin with this. The way to kick
- a player isnt much different from using the :Destroy() and :remove() command. To kick a player, you type
- their parent and the name of the player, then follow it by adding :Kick() All we are doing is changing
- the :Destroy()/:remove() to :Kick(). Lets see what it looks like in a script,
- game.Players.Player1:Kick() <-- This finds Parent "Players" and locates "Player1" then kicks them
- You could also do this with remove and destroy, however it allows the player to spectate the game, kick
- actually shuts down their game.
- Remember to use Players and not Workspace, this is because Players is not located in the Workspace.
- ------------------------------------------------------------------------------------------------------------
- Creating Strings -
- A string is a line of text, it's used to change any type of text such as messages, gui text, etc. A string
- can be used to edit things like names, text, values and so much more. Using a string is an easy process
- you simply type a name then an equal sign like so,
- OurVariable = ""
- OurVariable will be the variable we use, you can use strings multiple times in a script. Lets say we
- wanted to print our string and amke it say "Hello world!", we would type
- OurVariable = "Hello world!"
- print(OurVariable) <-- This finds the string "OurVariable" and prints it.
- Output would then print "Hello world!" as Hello world! is our string.
- ------------------------------------------------------------------------------------------------------------
- Local Scripts -
- A local script is a script that runs on an individual player rather than the server. You can use local
- scripts to configure something that goes on with a single player and so much more. Local scripts use a
- command known as "LocalPlayer". This tells the script that you want to get to the player that has the
- script. So it'd be scripted as,
- game.Players.LocalPlayer
- Leaving this will notify the script that you wish to connect to the player using the script. Local scripts
- can be placed into StarterGui, StarterTools, StarterPlayer, And you can even insert it manually. Lets say
- you wanted to kick a LocalPlayer, you would type,
- game.Players.LocalPlayer:Kick() <-- This kicks the player who has the script
- or you could do
- game.Players.LocalPlayer:Destroy() <-- Destroys the player who has the script
- What i mean by the script, If you look at this https://gyazo.com/95f6711476663ae72a358b7b759991f4 image
- if you but that script (AKA local script) into a player, playergui, starterpack or starterplayer, it runs
- on just them.
- ------------------------------------------------------------------------------------------------------------
- Scripting with Math -
- ROBLOX is full of secrets and surprises. But did you know its also a calculator? Lets print some equations,
- we will start with addition,
- print(3+3)
- Output will then display 6. Lets try making a message that does 3+3 then removes itself after 5 seconds.
- StringName = Instance.new("Message",game.Workspace) <-- Creates a new message in Workspace
- StringName.Text = 3+3 <-- Tells it the message to display
- wait(5) <-- Tells it to wait 5 seconds
- StringName:Destroy() <-- Destroys the message
- This would create a message, place it into workspace, make the text become 6, and destroy it after 5 seconds.
- You can also experiment with other math symbols. Heres the keys
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- ------------------------------------------------------------------------------------------------------------
- Variables and Strings -
- Although we have covered this, its better to get to know it more. So lets start by creating a variable.
- I will name my variable StringPlox. Lets give our variable a string and type something random in it,
- StringPlox = "I like cookies"
- This is an example of a string and variable. our variable is StringPlox and our string is "I like cookies"
- lets see, what can we use this for? Multiple things! Lets say we wanted to print our string, we would do,
- print(StringPlox)
- Or we can go further with it and create a hint with it!
- StringPlox= "I like cookies"
- Hnt = Instance.new("Hint",game.Workspace)
- Hnt.Text = StringPlox
- This would create a hint, insert it into workspace, and it would say I like cookies. But thats not all we
- can do with strings! Theres so much more.
- ------------------------------------------------------------------------------------------------------------
- More like text and values -
- Now lets try printing a text but not using a string. lets use a number value.
- PloxVal = 5
- print("I have"..PloxVal.."Cookies!")
- Or we could just use one set of
- PloxVal = 5
- print("I have this amount of cookies:"..PloxVal)
- This would display "I have this amount of cookies:5"
- Lets try using math like in our other lesson, but subtracting!
- PloxVal = 5
- ValPlox = 3
- print("I have this many cookies:"..PloxVal - ValPlox)
- Breakdown:
- Print = Creates a message in Output
- ("I have this many cookies:" = This is our string
- ..PloxVal =.. Seperates it, PloxVal is our Variable
- -ValPlox) = Subtracting the other variable.
- ------------------------------------------------------------------------------------------------------------
- Commenting -
- Commenting is probably the easiest thing you will learn, its very useful to find your place and keep up with
- everything. A comment will be displayed in green text and can be located anywhere in the script. So we will
- be learning two ways to comment. One will be for one like, and one will be for multiple lines. A comment is
- created by adding two minus signs like so --, This will create a comment by lests add text to it by doing,
- --Text Here
- --Text Here would be displayed in green. You can add spaces in this. That only occurs for one line, but lets
- say we wanted to do it with multiple lines and use one comment instead of saying -- over and over. We would
- type --[[, this would tell the script you are making a comment. So you would type your text after that and
- put ]] at the end.
- One line --Text goes here
- Multiple lines --[[Text goes here]]--
- ------------------------------------------------------------------------------------------------------------
- Cloning an Object -
- Cloning things arent really that difficult. In order to clone an object you will need to have some
- experience with variables. To clone, you need to get an objects parent followed by :clone() so lets say i
- wanted to clone a part in workspace. You would type
- game.Workspace.Part:clone()
- This would clone the part but its parent would be nil. To fix this, use a Variable like so.
- VariableName = game.Workspace.Part:clone()
- Remember you need to give the clone a parent. So to give it a parent you would do
- VariableName.Parent = game.Workspace
- ENTIRE SCRIPT:
- VariableName = game.Workspace.Part:clone()
- VariableName.Parent = game.Workspace
- OR
- game.Workspace.Part:clone().Parent = game.Workspace
- ------------------------------------------------------------------------------------------------------------
- Introduction to While -
- A whilce can run if a certain condition is met. Lets say i want to make a part constantly spawn only if
- game.Workspace.Part.Transparency = 1
- This basically means that it will spawn bricks only if the parts transparency is 1. While must not be
- capitalized at all, this breaks the script. One thing that a loop must always have is an end, it just tells
- the script thats where the loop ends. Dont forget your wait! Heres an example,
- while game.Workspace.Part.Transparency == 1 do
- wait(2)
- Instance.new("Part",game.Workspace)
- end
- You need to add TWO == signs to tell the script ONLY IF thats true then run the while.
- While repeats it, makes sure the part is 1 transparency, do is there to tell the script to DO
- Instance.new("Part) every single 2 seconds. If we change the game.Workspace.Part's transparency to 0,
- the loop would end right away.
- Imagine something running forever, endless. Nothing can stop it, thats where while true do comes in place.
- While true do is sort of like the code above, just no condition has to be met. Using while true do will tell
- the script that it can run forever like so,
- while true do
- wait(2)
- Instance.new("Part",game.Workspace)
- end
- This will simply create a part every 2 seconds and nothing has to meet a need. An easier way to type the code:
- Instead of typing true, you could do while wait (1) do. Example,
- while wait(1)
- Instance.new("Part",game.Workspace)
- end
- This also waits 1 second and then creates a part endless amounts of times.
- ------------------------------------------------------------------------------------------------------------
- Introduction to for -
- A for is how we limit our scripts run times. using a for can allow us to tell the script that we want to run
- a certain code this amny times or that many times, or whatever you have in mind. Just like while, a for must
- have a wait also, or it will crash. A for must also come with an end. To create a for loop you must type for
- then a variable you wish to create, we will use "Derp" as the variable.
- for Derp
- Followed by Derp you type an equal sign, once ive done that you type how many times the script will run each
- loop. By this i mean, if i wanted to run the script twice every second,
- for Derp = 2
- Once youve done that, you'll type a comma then how many times of each set of 2 runs, I'll use 10, heres how
- youd type it.
- for Derp = 2,10
- Now you must type do, your code, and an end.
- for Derp = 2,10 do
- wait(1)
- print("Hello")
- end
- This simply runs the same script two times every 1 second, the script stops after 10 seconds, this would print
- Hello 20 times.
- Lets break down how a for works.
- for Derp = 2,10 do
- wait(1)
- print("Hi")
- end
- This will print "Hi" every two seconds 10 times. Each second, this will print "Hi" TWO times, TEN times.
- The script will basically run itself 20 times in 10 seconds. 2 x 10. Lets try using 1.
- for Derp = 1,10 do
- wait(1)
- print("Hi")
- end
- As you know this will print Hi every 1 second but only 10 times.
- ------------------------------------------------------------------------------------------------------------
- Work with Repeats -
- Repeating isnt much different from using while true do. Basically it uses sort of the same concept. if a
- condition is met, it will stop. So to use a repeat you type repeat followed by your code.
- repeat
- print("Im repeating!")
- This wont work yet because we need something to end it, so do this, youd type until. So until is like. I
- wont allow this loop to stop until something else occurs. So i'll let this loop stop when
- game.Workspace.Part.Transparency = .1
- repeat
- print("Im repeating!")
- until game.Workspace.Part.Transparency == 1
- With repeating, youd need to add two == signs, this will tell the script thats 1 then it will stop.
- Breakdown:
- repeat -- repeats the loop
- print("Im repeating") -- this is where your code goes
- until game.Workspace.Part.Transparency == 1 -- This will stop it from printing
- ------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement