Advertisement
Guest User

Rblx scripts

a guest
Nov 11th, 2024
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.49 KB | None | 0 0
  1. -
  2. Download Here --> https://tinyurl.com/rhf4x3dp (Copy and Paste Link)
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. Introduction to Scripting
  10. In Introduction to Roblox Studio , you learned how to create and manipulate parts in Roblox Studio. In this tutorial, you'll learn how to apply a script to parts to make a platform appear and disappear. You can use this in a platforming experience to span a gap, challenging users to time their jumps carefully to get to the other side.
  11. Setting the Scene
  12. First off, you need a Part to act as the platform. Making and moving parts should be familiar to you from Introduction to Roblox Studio . You don't need a complicated world aside from the platform — you just need a gap that your users can't easily jump across.
  13. Remember that setting a part's Anchored property to true makes it stay in place no matter what. Your platform falls down if it's not anchored.
  14. Inserting a Script
  15. Code in Roblox is written in a language called Lua , and it's stored and run from scripts. You can put scripts in various containers in the Explorer . If you put a script under a Part , Roblox will run the code in the script when the part is loaded into the game.
  16. Hover over the DisappearingPlatform part in the Explorer window and click the + button to insert a new script into the platform. Rename your new script as Disappear .
  17. Remember to rename parts and scripts as soon as you create them so you don't lose track of things in the Explorer .
  18. First Variable
  19. It's a good idea to start off your script by making a variable for the platform. A variable is a name associated with a value . Once a variable is created, it can be used again and again. You can change the value as needed.
  20. In Lua, a variable is created as follows: local variableName = variableValue .
  21. The term local means that the variable is only going to be used in the block of the script where it's declared. The = sign is used to set the value of the variable. Names for variables are typically written in camel case . This is lowercase with every word following the first being capitalized, justLikeThis .
  22. Copy the following code to create a variable for the platform called platform . where the value is script.Parent .
  23. local platform = script.Parent
  24. script.Parent is used to find the object the script is located in. As you might have guessed, script refers to the script you're writing in and the Parent of the script is where it's located.
  25. Disappear Function
  26. Time to make the platform disappear. It's always best to group code for achieving a specific action into a function . A function is a named block of code that helps you organize your code and use it in multiple places without writing it again. Create a function in the script and call it disappear .
  27. local platform = script.Parent local function disappear() end
  28. The first new line declares the function — it indicates the start of the function and names it as disappear . The code for a function goes between the first line and end .
  29. The parentheses are for including additional information as needed. You'll learn more about passing information to functions in a later course.
  30. Part Properties
  31. When the platform disappears, it needs to be invisible and users need to fall through it — but you can't just destroy the platform since it needs to reappear later.
  32. Parts have various properties that can be used here. Remember that you can see a part's properties if you select it and look at the Properties window.
  33. A part can be made invisible by changing the Transparency property. Transparency can be a value between 0 and 1, where 1 is fully transparent and therefore invisible.
  34. Changing the Transparency property of the cube
  35. The CanCollide property determines if other parts (and users) can pass right through the part. If you set it to false , users will fall through the platform.
  36. Changing the CanCollide property of the cube
  37. Just like script.Parent , properties are accessed using a dot . Values are assigned using an equals sign.
  38. local platform = script.Parent local function disappear() platform.CanCollide = false platform.Transparency = 1 end
  39. You might notice that Studio automatically indents your code inside a function. Always make sure to indent your code like this — it helps indicate where the function begins and ends that makes your code more readable.
  40. Calling the Function
  41. Once you've declared a function, you can run it by writing its name with parentheses next to it. For example, disappear() will run the disappear function. This is known as calling a function.
  42. local platform = script.Parent local function disappear() platform.CanCollide = false platform.Transparency = 1 end disappear()
  43. Test the code by pressing the Play button. If your code works, the platform should have disappeared by the time the user spawns into the game.
  44. Appear Function
  45. You can easily make the platform reappear by writing a function which does the exact opposite of the disappear function.
  46. local platform = script.Parent local function disappear() platform.CanCollide = false platform.Transparency = 1 end local function appear() platform.CanCollide = true platform.Transparency = 0 end
  47. Looping Code
  48. The platform should be constantly disappearing and reappearing, with a few seconds between each change. It's impossible to write an infinite number of function calls — fortunately, with a while loop , you don't have to.
  49. A while loop runs the code inside it for as long as the statement after while remains true. This particular loop needs to run forever, so the statement should just be true . Create a while true loop at the end of your script.
  50. local platform = script.Parent local function disappear() platform.CanCollide = false platform.Transparency = 1 end local function appear() platform.CanCollide = true platform.Transparency = 0 end while true do end
  51. Toggling the Platform
  52. In the while loop, you need to write code to wait a few seconds between the platform disappearing and reappearing.
  53. The built-in function wait can be used for this. In the parentheses the number of seconds to wait is needed: for example wait(3) .
  54. Whatever you do, never make a while true loop without including a wait — and don't test your code before you've put one in! If you don't wait, your game will freeze because Studio will never have a chance to leave the loop and do anything else.
  55. Three seconds is a sensible starting point for the length of time between each platform state.
  56. while true do wait(3) disappear() wait(3) appear() end
  57. The code for the platform is now complete! Test your code now and you should find that the platform disappears after three seconds and reappears three seconds later in a loop.
  58. You could duplicate this platform to cover a wider gap, but you need to change the wait times in each script, otherwise the platforms will all disappear at the same time and users will never be able to cross.
  59. Final Code
  60. local platform = script.Parent local function disappear() platform.CanCollide = false platform.Transparency = 1 end local function appear() platform.CanCollide = true platform.Transparency = 0 end while true do wait(3) disappear() wait(3) appear() end
  61. Script Editor
  62. The Script Editor in Studio is the primary tool for scripting on Roblox. It's a self-improving environment that can help you write high-impact code, shorten your development time, and iterate on your experiences. It can improve your scripting experience by:
  63. The Script Editor supports all types of scripts and opens automatically when you create a new script or double-click an existing script in the Explorer window.
  64. Autocomplete
  65. The Script Editor generates code-related information that can improve your programming efficiency. It offers suggestions on how to complete phrases as you type them. Use the up and down arrow keys to browse the suggestions, then press Tab or Enter to accept a suggestion and insert the complete phrase.
  66. The Script Editor is tied to the 3D environment in Studio. If you have a Part in Workspace called CoolRocketShip , then autocomplete suggests CoolRocketShip when you type workspace.cool and indicates that it's a Part .
  67. Autocomplete also offers names for variables and functions that you declare, making it easier to avoid typos and reuse code.
  68. Documentation
  69. The autocomplete pop-up provides documentation and code samples similar to those on the Engine API Reference , providing you with context on an API's usage.
  70. Signature Help
  71. When you type an argument into a function, the autocomplete pop-up also shows the function's signature, providing you with a reference for its parameters and return values.
  72. Code Navigation
  73. The Script Editor provides multiple ways to navigate your variable and function declarations.
  74. Go to Declaration
  75. You can jump to the declaration of a function or variable by right-clicking its call and clicking Go to Declaration . You can also jump to a declaration by holding Ctrl on Windows or ⌘ on macOS when clicking the call.
  76. Script Function Filter
  77. The Script Function Filter displays a list of functions declared in a script. To open it, right-click anywhere in the editor, then click Script Function Filter . With the list open, you can browse the signatures for each function, filter through them by name, and double-click one to jump to its declaration.
  78. Find and Replace
  79. The Find and Replace widget lets you find and replace code in an open script. The widget supports matching case, matching the whole word, and regular expressions. To open the Find and Replace widget, press Ctrl + F on Windows or ⌘ + F on macOS.
  80. Find All / Replace All
  81. The Find All / Replace All window lets you find and replace code in all scripts in an place. The window supports matching case, matching the whole word, and regular expressions. To open the Find All / Replace All window, open the View tab and click Find All / Replace All .
  82. Real-Time Feedback
  83. The Script Editor can help you learn Luau faster by providing real-time feedback with the Script Analysis and Output windows.
  84. Script Analysis
  85. The Script Analysis window, accessible from the View tab, performs static analysis on your scripts and displays active errors and warnings. To display only the errors and warnings for the current script, toggle the "Display only current script" checkbox. For more information on the errors and warnings, see the Luau Lang documentation .
  86. Output
  87. The Output window, accessible from the View tab, displays errors captured from running scripts, messages from Roblox engine, messages from calls to print() , and errors from calls to warn() . For information on how to configure it for your workflow, see Output .
  88. Code Assist
  89. This feature is currently in beta. To use it, go to File → Beta Features and enable AI-Powered Code Completion .
  90. Code Assist is an AI assistant that suggests lines or functions of code as you type, helping you code more efficiently and stay focused. Based on contexts from your comment and code, suggestions will be triggered in two ways:
  91. Automatically when you pause on a line for a few seconds and the AI model has enough context for a suggestion.
  92. Press Tab to accept a suggestion, or ignore it by continuing to type. Currently, your script needs to contain at least a few lines of code to trigger a suggestion.
  93. Code Assist helps automate basic coding tasks so you can focus on creative work, but it does not always suggest perfect code (see Limitations ) . It's still your responsibility to review, test, and determine if the code suggestion is contextually appropriate.
  94. Improving Suggestions
  95. To get more accurate and relevant suggestions, it's recommended that you follow clean coding practices, regardless of AI assistance, and:
  96. Use descriptive script names that capture the overall intent of what each script does. For example, name a script SyncCustomSounds instead of just Sounds .
  97. Assign descriptive names for parameters, functions, and scripts. For example, name a part GreenSphere instead of simply grs , or name a function generateSphere() instead of gen() . Using named functions versus anonymous functions can also produce better hints.
  98. Use the exact function or variable name you defined, for example -- Create 10 greenSphere objects instead of -- Create 10 spheres .
  99. If you're a novice scripter, start with basic projects such as "make the player jump when they touch the part" or use the tool to generate small code snippets that you can expand upon as your knowledge grows.
  100. Limitations
  101. The tool helps automate basic coding tasks but it does not always suggest perfect code. Known limitations include:
  102. Suggestions are machine learned from a corpus of code and can thus reflect some limitations of the code they're trained on. For example, suggestions may not use newer APIs in favor of older APIs, or they may use Lua instead of Luau .
  103. Internal filters attempt to block offensive language, but they're not all-encompassing and there's a possibility the tool may generate offensive or biased information.
  104. The suggestions may be the same, similar, or different among users, even with the same prompts. Your code, however, will never be shared with others.
  105. There's a daily cap for the number of suggestions and, once the cap is reached, you will get no suggestions until the next day.
  106. Code Privacy
  107. Currently, Roblox does not use any non-public data to train the learning models. The tool only uses a small subset of free marketplace assets for tuning large language models and the subset has passed various checks for quality and safety filters.
  108. Furthermore, all suggestions are generated by the AI model and do not transfer from one user to another. Since your code is not used for model training, it won't be suggested to other users of Code Assist , with the one exception of code being posted to free marketplace items.
  109. Multi-Cursor
  110. The Script Editor supports the use of multiple cursors to make edits simultaneously. You can add cursors based on your needs with a mouse click or keyboard shortcut. The initial cursor is called the primary cursor , and additional cursors are called secondary cursors . All lines with a cursor are highlighted. The edits at the primary cursor copy to the secondary cursors. Widgets such as Autocomplete appear on the primary cursor but not the secondary cursors.
  111. In multi-cursor editing, each edit counts as one edit even if you have multiple cursors. If you undo or redo an edit while using multi-cursor editing, the undo or redo applies to all cursors. The standard keyboard shortcuts for editing in Script Editor, such as indenting code, toggling comments, and deleting lines, all work with multi-cursor editing.
  112. To remove all secondary cursors, exit multi-cursor editing, and return to the primary cursor, press Esc .
  113. Multi-Cursor Script Editing is in beta. To enable the beta in Studio, go to File > Beta Features , and enable Multi-Cursor Script Editing .
  114. Adding Cursors
  115. You can add cursors with a combination of keyboard shortcuts and mouse maneuvers. Cursors merge if they occupy the same space, such as if you add cursors with arrow keys or delete all the characters between cursors.
  116. At Mouse Location
  117. To add a cursor at your mouse:
  118. With Mouse Drag
  119. To add a cursor to a selection of text:
  120. Above and Below Primary Cursor
  121. To add a cursor directly above or below the primary cursor:
  122. To All Matching Selections
  123. To add a cursor to all matching selections:
  124. To Next Matching Selection
  125. To add a cursor to the next matching selection:
  126. To Previous Matching Selection
  127. To add a cursor to the previous matching selection:
  128. You can also create a shortcut of your choice by opening the Customize Shortcuts window in File > Advanced > Customize Shortcuts and editing the shortcut for "Select previous occurrence".
  129. To Selected Line Ends and Selection End
  130. To add cursors at the end of each line in a multi-line selection and at the end of the selection:
  131. Removing Cursors
  132. You can remove cursors with a combination of keyboard shortcuts and mouse maneuvers. To remove all secondary cursors and exit multi-cursor editing, press Esc or click anywhere in the Script Editor.
  133. At Mouse Location
  134. Most Recently Added
  135. To remove the most recently added cursor, press Ctrl + U on Windows or ⌥ + U on macOS.
  136. Copying and Pasting Cursors
  137. Copying a selection of text includes the cursors within it. The behavior of the paste depends on the number of cursors at the source and the number of cursors at the destination:
  138. If the number of cursors are the same, then each copied cursor pastes to each corresponding destination cursor.
  139. If the number of cursors are different, then each cursor at the destination receives the entire paste with each copied cursor as a new line.
  140. Customization
  141. The Script Editor offers a wide array of settings, so you can customize it to suit your preferences and workflows. For example, you can configure aesthetics such as the font family and size, formatting behavior, and colors for syntax highlighting. You can also toggle features such as Autocomplete , Signature Help , and Script Analysis .
  142. To open the settings, click File , click Studio Settings , then click Script Editor . You can also press Alt + S on Windows or ⌥ + S on macOS.
  143. Keyboard Shortcuts
  144. The Script Editor has the following keyboard shortcuts. You can also access many commands by right-clicking anywhere in the editor.
  145. General
  146. Command Windows macOSClose Script Ctrl + W ⌘ + W Reopen Last Closed Script Ctrl + Shift + T ⌘ + Shift + T Quick Open, Go to File. Ctrl + P ⌘ + P Show in Explorer Ctrl + Alt + K ⌥ + ⌘ + K Studio Settings Alt + S ⌥ + S
  147. Basic Editing
  148. Command Windows macOSUndo Ctrl + Z ⌘ + Z Redo Ctrl + Y Shift + ⌘ + Z Cut Ctrl + X ⌘ + X Copy Ctrl + C ⌘ + C Paste Ctrl + V ⌘ + V Select All Ctrl + A ⌘ + A Format Selection Alt + Shift + F ⌥ + Shift + F Indent Ctrl + ] ⌘ + ] Unindent Ctrl + [ ⌘ + [ Toggle Comment Ctrl + / ⌘ + / Expand All Folds Ctrl + E ⌘ + E Collapse All Folds Ctrl + Shift + E ⌘ + Shift + E Delete Line Ctrl + Shift + K ⌘ + Shift + K Delete to Start of Line Ctrl + Shift + Backspace ⌘ + Delete Move Line Up/Down Alt + Up/Down Option+ + Up/Down Go to Declaration Ctrl + F12 ⌘ + F12 Open Script Function Filter Alt + F ⌥ + F
  149. Multi-Cursor Editing
  150. Command Windows macOSAdd or Remove Cursor at Mouse Location Alt + click ⌥ + clickAdd Cursor with Mouse Drag Alt + click and drag ⌥ + click and dragAdd Cursor Above Primary Cursor Ctrl + Alt + ↑ ⌘ + ⌥ + ↑ Add Cursor Below Primary Cursor Ctrl + Alt + ↓ ⌘ + ⌥ + ↓ Add Cursor to All Matching Selections Shift + Alt + L Shift + ⌥ + L Add Cursor to Next Matching Selection Ctrl + D ⌘ + D Add Cursors to Selected Line Ends and Selection End Shift + Alt + I Shift + ⌥ + I Remove Most Recently Added Cursor Ctrl + U ⌘ + U
  151. Display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement