Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.43 KB | None | 0 0
  1. --By Anthony--
  2.  
  3. Scripting help for myself and others.
  4. I will be covering basics which allow me to learn from them and refer to.
  5.  
  6.  
  7. Parents -
  8. A parent is any object in the game. Workspace is the most often used parent which holds the character
  9. and the bricks that you see.
  10.  
  11. The Workspace's Parent is game. Example --> game.Workspace.Player1 <-- This finds Player1's Character and goes
  12. through its parents which is --> game.Workspace <-- which is basically its location.
  13.  
  14. Visual Explanation ---> https://gyazo.com/e7d9de20567cd5451564a207cfbf1985 <--- game.Workspace.Baseplate is the
  15. location of the Baseplate.
  16.  
  17. Things to remember about Parents. "game" not "Game"
  18. "Workspace" not "workspace"
  19. Remember to seperate with .
  20.  
  21. ------------------------------------------------------------------------------------------------------------
  22.  
  23. Using Instances -
  24. Instances are how someone inserts something into the game without manually inserting it. Scripters choose to
  25. insert things like Values and Parts by using a script. The way this is done is by typing "Instance.new" inside
  26. of your script. (Without the "") This tells the script that im about to create something from advanced models.
  27. You will need to put the name exactly how it is because they are case sensitive.
  28.  
  29. So now we know that Instance.New is how to create something, we can specify what we want,
  30. for example Instance.new("Part") this code would create a part, but it wouldnt be visible because it has no parent.
  31. So we give it a parent by putting Instance.new("Part"),game.Workspace) This tells it to put the part into
  32. game.Workspace where bricks are visibly seen by players.
  33.  
  34. Visual representation - --> https://gyazo.com/841c33311c196f0b0b857102c3b039b2 <--
  35.  
  36. Things to remember about Instances. Ensure the i in Instance is capitalised
  37. Ensure the n in new is lowercase
  38. Ensure the item im inserting is case sensitive
  39.  
  40. ------------------------------------------------------------------------------------------------------------
  41.  
  42. Configuring Properties -
  43. A property is just settings of an advanced object. So for instance, you have properties known as position,
  44. transparency, size, name and more. So we will work with transparency and reflectance then move on to naming
  45. and strings.
  46.  
  47. So lets begin by inserting a brick into Workspace, like the picture shows in frame one. So inside the script type
  48. the parent of the brick (game.Workspace.Part) then follow by adding .Transparency =.5 so it will be
  49. game.Workspace.Part.Transparency = .5 this will make the object known as "Part" 50% visible. The same process
  50. works with reflectance. game.Workspace.Part.Reflectance = .5 .
  51.  
  52. Things to note - If i have multiple objects named part, it will choose one at random.
  53.  
  54. Chaging the material property is a little harder. "Material property" is game.Workspace.Part followed by .Material.
  55. So it will be game.Workspace.Part.Material. Once ive done that, i can give it a material. E.g. "Grass".
  56. So it will be "game.Workspace.Part.Material = "Grass" This tells the script that i want the material to be grass.
  57. Other materials consist of the official materials e.g Slate, Sand, Wood, Foil, Metal etc.
  58.  
  59. ------------------------------------------------------------------------------------------------------------
  60.  
  61. Destroying and Removing -
  62. Remove is a commonly used command to delete an object permanently as destroy makes its parent nil (Has no parent)
  63. which means that both of them remove the object.To remove an object, you locate its parent and follow it by typing
  64. :remove() or :Destroy(). This removes or destroys the object. Example: game.Workspace.Model:remove() <-- Removes
  65. the model. game.Workspace.Model:Destroy() <-- Destroys the model.
  66.  
  67. ------------------------------------------------------------------------------------------------------------
  68.  
  69. Learning the Output -
  70. The output is the scripters best friend, it displays all types of problems with the game and things that are possibly
  71. wrong with the script. It can also help you test things to see if any part of the script errors.
  72. Setting it up: Open Studio > View > Output
  73. Many scripters use print to find errors in their scripts, in a script, the word print is just an option to put text
  74. in the output. So if i type print("Chocolate") it would appear in the output as the word "Chocolate". You can use
  75. print to do mathmatic calculations and to test if your scripts are working, also to debug.
  76.  
  77. Visual Example - https://gyazo.com/1147b1cec892242e870420e08fb9b9c4
  78.  
  79. ------------------------------------------------------------------------------------------------------------
  80.  
  81. Using and creating variables -
  82. A variable is a holder, it holds data. Just like a storage, a variable can be many things. We create a variable by
  83. typing VariableName = . VariableName can be anything. So try HelloWorld as the variable. In variables, you can
  84. hold strings, numbers, parents, and all kinds of things. Lets say for instance we wanted to hold a number,
  85. we would type
  86. Number:
  87. HelloWorld = 5
  88. Parent:
  89. HelloWorld = game.Workspace
  90. String:
  91. HelloWorld = "I love Cookies!"
  92.  
  93. ------------------------------------------------------------------------------------------------------------
  94.  
  95. Working with Bool Values -
  96. A bool value is a simple true or false, for instance, lets use Anchored as an example. Anchored uses true or false
  97. to choose whether it is or isnt. Example:
  98. Instance.new("Part",game.Workspace) <--- This tells the game to create a part in Workspace
  99. game.Workspace.Part.Anchored = true <--- This tells the game to anchor that said part.
  100. This would make the brick anchor itself, same goes with CanCollide
  101. Instance.new("Part",game.Workspace) <--- This tells the game to create a part in Workspace
  102. game.Workspace.Part.CanCollide = true <--- This tells the game to make the part CanCollide
  103. A bool value can be used for endless possibilities.
  104.  
  105. ------------------------------------------------------------------------------------------------------------
  106.  
  107. Editing Lighting -
  108. GlobalShadows and Outlines are properties that use the bool value, to configure these you would type
  109. game.Lighting.GlobalShadows = false <-- Disables GlobalShadows
  110. game.Lighting.Outlines = false <-- Disables Outlines
  111. You can also configure the brightness by typing
  112. game.Lighting.brightness = 2 <--- This is the brightness of the game
  113. Another simple property that is easily edited is FogEnd or FogStart
  114. game.Lighting.FogEnd = 1234
  115. game.Lighting.FogStart = 4321
  116.  
  117. ------------------------------------------------------------------------------------------------------------
  118.  
  119. Adding a Wait Value -
  120. A wait is used to control the script on a timed basis. For instance, you can make a script that creates
  121. a brick, changes its transparency to .5 after 3 seconds, then deletes itself after another three seconds.
  122. To do this, youd type
  123. Instance.new("Part",game.Workspace) <-- This creates the part
  124. wait(3) <-- This tells the script to wait for 3 seconds
  125. game.Workspace.Part.Transparency = .5 <-- This changes the transparency to 0.5
  126. wait(3) <-- This tells the script to wait for 3 seconds
  127. game.Workspace.Part:Destroy() <-- This destroys the part
  128. This would create a brick, make its transparency .5 after a 3 second delay, and then remove it after another
  129. 3 seconds. Wait must be "wait" as lowercase otherwise it will error. Instead of "Wait" you put "wait".
  130. Wait - Wrong
  131. wait - right.
  132. You can use waits for VIP doors, guis, messages and much, much more.
  133.  
  134. ------------------------------------------------------------------------------------------------------------
  135.  
  136. Editing an Instance -
  137. Editing an instance isnt much different from creating one. The way to do this is simply by adding one little
  138. bit of coding. So lets say we want to create a part and anchor it, we would type
  139. Instance.new("Part",game.Workspace) And then follow it with .Anchored = true
  140. Full code
  141. Instance.new("Part",game.Workspace).Anchored = true <-- Creates a part and anchors it
  142. This will anchor the part as if it was
  143. game.Workspace.Part.Anchored = true <-- This way also works
  144. You can also do things like
  145. Instance.new("Part",game.Workspace).Transparency = .5
  146. Or
  147. game.Workspace.Part.Transparency = .5
  148. Also you can do
  149. Instance.new("Part",game.Workspace).Name = "Brick" <-- This creates a brick and renames it
  150.  
  151. ------------------------------------------------------------------------------------------------------------
  152.  
  153. Kicking a player -
  154. Kicking a player isnt hard at all, you can possibly even create your own admin with this. The way to kick
  155. a player isnt much different from using the :Destroy() and :remove() command. To kick a player, you type
  156. their parent and the name of the player, then follow it by adding :Kick() All we are doing is changing
  157. the :Destroy()/:remove() to :Kick(). Lets see what it looks like in a script,
  158. game.Players.Player1:Kick() <-- This finds Parent "Players" and locates "Player1" then kicks them
  159. You could also do this with remove and destroy, however it allows the player to spectate the game, kick
  160. actually shuts down their game.
  161. Remember to use Players and not Workspace, this is because Players is not located in the Workspace.
  162.  
  163. ------------------------------------------------------------------------------------------------------------
  164.  
  165. Creating Strings -
  166. A string is a line of text, it's used to change any type of text such as messages, gui text, etc. A string
  167. can be used to edit things like names, text, values and so much more. Using a string is an easy process
  168. you simply type a name then an equal sign like so,
  169. OurVariable = ""
  170. OurVariable will be the variable we use, you can use strings multiple times in a script. Lets say we
  171. wanted to print our string and amke it say "Hello world!", we would type
  172. OurVariable = "Hello world!"
  173. print(OurVariable) <-- This finds the string "OurVariable" and prints it.
  174. Output would then print "Hello world!" as Hello world! is our string.
  175.  
  176.  
  177. ------------------------------------------------------------------------------------------------------------
  178.  
  179. Local Scripts -
  180. A local script is a script that runs on an individual player rather than the server. You can use local
  181. scripts to configure something that goes on with a single player and so much more. Local scripts use a
  182. command known as "LocalPlayer". This tells the script that you want to get to the player that has the
  183. script. So it'd be scripted as,
  184. game.Players.LocalPlayer
  185. Leaving this will notify the script that you wish to connect to the player using the script. Local scripts
  186. can be placed into StarterGui, StarterTools, StarterPlayer, And you can even insert it manually. Lets say
  187. you wanted to kick a LocalPlayer, you would type,
  188. game.Players.LocalPlayer:Kick() <-- This kicks the player who has the script
  189. or you could do
  190. game.Players.LocalPlayer:Destroy() <-- Destroys the player who has the script
  191. What i mean by the script, If you look at this https://gyazo.com/95f6711476663ae72a358b7b759991f4 image
  192. if you but that script (AKA local script) into a player, playergui, starterpack or starterplayer, it runs
  193. on just them.
  194.  
  195. ------------------------------------------------------------------------------------------------------------
  196.  
  197. Scripting with Math -
  198. ROBLOX is full of secrets and surprises. But did you know its also a calculator? Lets print some equations,
  199. we will start with addition,
  200. print(3+3)
  201. Output will then display 6. Lets try making a message that does 3+3 then removes itself after 5 seconds.
  202. StringName = Instance.new("Message",game.Workspace) <-- Creates a new message in Workspace
  203. StringName.Text = 3+3 <-- Tells it the message to display
  204. wait(5) <-- Tells it to wait 5 seconds
  205. StringName:Destroy() <-- Destroys the message
  206. This would create a message, place it into workspace, make the text become 6, and destroy it after 5 seconds.
  207. You can also experiment with other math symbols. Heres the keys
  208. Addition: +
  209. Subtraction: -
  210. Multiplication: *
  211. Division: /
  212.  
  213. ------------------------------------------------------------------------------------------------------------
  214.  
  215. Variables and Strings -
  216. Although we have covered this, its better to get to know it more. So lets start by creating a variable.
  217. I will name my variable StringPlox. Lets give our variable a string and type something random in it,
  218. StringPlox = "I like cookies"
  219. This is an example of a string and variable. our variable is StringPlox and our string is "I like cookies"
  220. lets see, what can we use this for? Multiple things! Lets say we wanted to print our string, we would do,
  221. print(StringPlox)
  222. Or we can go further with it and create a hint with it!
  223. StringPlox= "I like cookies"
  224. Hnt = Instance.new("Hint",game.Workspace)
  225. Hnt.Text = StringPlox
  226. This would create a hint, insert it into workspace, and it would say I like cookies. But thats not all we
  227. can do with strings! Theres so much more.
  228.  
  229. ------------------------------------------------------------------------------------------------------------
  230.  
  231. More like text and values -
  232. Now lets try printing a text but not using a string. lets use a number value.
  233. PloxVal = 5
  234. print("I have"..PloxVal.."Cookies!")
  235. Or we could just use one set of
  236. PloxVal = 5
  237. print("I have this amount of cookies:"..PloxVal)
  238. This would display "I have this amount of cookies:5"
  239. Lets try using math like in our other lesson, but subtracting!
  240. PloxVal = 5
  241. ValPlox = 3
  242. print("I have this many cookies:"..PloxVal - ValPlox)
  243. Breakdown:
  244. Print = Creates a message in Output
  245. ("I have this many cookies:" = This is our string
  246. ..PloxVal =.. Seperates it, PloxVal is our Variable
  247. -ValPlox) = Subtracting the other variable.
  248.  
  249. ------------------------------------------------------------------------------------------------------------
  250.  
  251. Commenting -
  252. Commenting is probably the easiest thing you will learn, its very useful to find your place and keep up with
  253. everything. A comment will be displayed in green text and can be located anywhere in the script. So we will
  254. be learning two ways to comment. One will be for one like, and one will be for multiple lines. A comment is
  255. created by adding two minus signs like so --, This will create a comment by lests add text to it by doing,
  256. --Text Here
  257. --Text Here would be displayed in green. You can add spaces in this. That only occurs for one line, but lets
  258. say we wanted to do it with multiple lines and use one comment instead of saying -- over and over. We would
  259. type --[[, this would tell the script you are making a comment. So you would type your text after that and
  260. put ]] at the end.
  261. One line --Text goes here
  262. Multiple lines --[[Text goes here]]--
  263.  
  264. ------------------------------------------------------------------------------------------------------------
  265.  
  266. Cloning an Object -
  267. Cloning things arent really that difficult. In order to clone an object you will need to have some
  268. experience with variables. To clone, you need to get an objects parent followed by :clone() so lets say i
  269. wanted to clone a part in workspace. You would type
  270. game.Workspace.Part:clone()
  271. This would clone the part but its parent would be nil. To fix this, use a Variable like so.
  272. VariableName = game.Workspace.Part:clone()
  273. Remember you need to give the clone a parent. So to give it a parent you would do
  274. VariableName.Parent = game.Workspace
  275. ENTIRE SCRIPT:
  276. VariableName = game.Workspace.Part:clone()
  277. VariableName.Parent = game.Workspace
  278. OR
  279. game.Workspace.Part:clone().Parent = game.Workspace
  280.  
  281. ------------------------------------------------------------------------------------------------------------
  282.  
  283. Introduction to While -
  284. A whilce can run if a certain condition is met. Lets say i want to make a part constantly spawn only if
  285. game.Workspace.Part.Transparency = 1
  286. This basically means that it will spawn bricks only if the parts transparency is 1. While must not be
  287. capitalized at all, this breaks the script. One thing that a loop must always have is an end, it just tells
  288. the script thats where the loop ends. Dont forget your wait! Heres an example,
  289. while game.Workspace.Part.Transparency == 1 do
  290. wait(2)
  291. Instance.new("Part",game.Workspace)
  292. end
  293. You need to add TWO == signs to tell the script ONLY IF thats true then run the while.
  294. While repeats it, makes sure the part is 1 transparency, do is there to tell the script to DO
  295. Instance.new("Part) every single 2 seconds. If we change the game.Workspace.Part's transparency to 0,
  296. the loop would end right away.
  297.  
  298. Imagine something running forever, endless. Nothing can stop it, thats where while true do comes in place.
  299. While true do is sort of like the code above, just no condition has to be met. Using while true do will tell
  300. the script that it can run forever like so,
  301. while true do
  302. wait(2)
  303. Instance.new("Part",game.Workspace)
  304. end
  305. This will simply create a part every 2 seconds and nothing has to meet a need. An easier way to type the code:
  306. Instead of typing true, you could do while wait (1) do. Example,
  307. while wait(1)
  308. Instance.new("Part",game.Workspace)
  309. end
  310. This also waits 1 second and then creates a part endless amounts of times.
  311.  
  312. ------------------------------------------------------------------------------------------------------------
  313.  
  314. Introduction to for -
  315. 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
  316. a certain code this amny times or that many times, or whatever you have in mind. Just like while, a for must
  317. 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
  318. then a variable you wish to create, we will use "Derp" as the variable.
  319. for Derp
  320. Followed by Derp you type an equal sign, once ive done that you type how many times the script will run each
  321. loop. By this i mean, if i wanted to run the script twice every second,
  322. for Derp = 2
  323. 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
  324. youd type it.
  325. for Derp = 2,10
  326. Now you must type do, your code, and an end.
  327. for Derp = 2,10 do
  328. wait(1)
  329. print("Hello")
  330. end
  331. This simply runs the same script two times every 1 second, the script stops after 10 seconds, this would print
  332. Hello 20 times.
  333.  
  334. Lets break down how a for works.
  335. for Derp = 2,10 do
  336. wait(1)
  337. print("Hi")
  338. end
  339. This will print "Hi" every two seconds 10 times. Each second, this will print "Hi" TWO times, TEN times.
  340. The script will basically run itself 20 times in 10 seconds. 2 x 10. Lets try using 1.
  341. for Derp = 1,10 do
  342. wait(1)
  343. print("Hi")
  344. end
  345. As you know this will print Hi every 1 second but only 10 times.
  346.  
  347. ------------------------------------------------------------------------------------------------------------
  348.  
  349. Work with Repeats -
  350. Repeating isnt much different from using while true do. Basically it uses sort of the same concept. if a
  351. condition is met, it will stop. So to use a repeat you type repeat followed by your code.
  352. repeat
  353. print("Im repeating!")
  354. This wont work yet because we need something to end it, so do this, youd type until. So until is like. I
  355. wont allow this loop to stop until something else occurs. So i'll let this loop stop when
  356. game.Workspace.Part.Transparency = .1
  357.  
  358. repeat
  359. print("Im repeating!")
  360. until game.Workspace.Part.Transparency == 1
  361. With repeating, youd need to add two == signs, this will tell the script thats 1 then it will stop.
  362.  
  363. Breakdown:
  364. repeat -- repeats the loop
  365. print("Im repeating") -- this is where your code goes
  366. until game.Workspace.Part.Transparency == 1 -- This will stop it from printing
  367.  
  368. ------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement