RetroStudio Documentation
Code BlocksObjectsGuides
  • Index
  • Code Blocks
    • Code Block Index
    • Actions
      • General
        • Set Object Property
        • Get Object Property
        • Tween Object Property
        • Create Object
        • Destroy Object
        • Clone Object
        • Is A
        • Is Touching
        • Get Touching Parts
        • Get Connected Parts
      • Hierarchy
        • Find First Child
        • Find First Child Which IsA
        • Find First Child Of Class
        • Wait For Child
        • Get Random Child
        • Get Children
        • Get Descendants
        • Is Descendant Of
        • Is Ancestor Of
      • Physics
        • Make Joints
        • Break Joints
        • Set Part Network Owner
        • Find Part On Ray
        • Set Part Physical Properties
        • Get Part Physical Properties
        • Fire Rocket Propulsion
        • Abort Rocket Propulsion
      • Models
        • Move Model To
        • Set Model PrimaryPart CFrame
        • Get Model Bounding Box
      • Sounds
        • Play Sound
        • Stop Sound
        • Pause Sound
        • Resume Sound
      • Leaderstats
        • Create Leaderstat
        • Get Leaderstat
    • Input
      • Mouse
        • Click Detector Interaction
        • Get Mouse Target Part
        • Get Mouse Target Surface
        • Get Mouse Position 2D
        • Get Mouse Position 3D
        • Left Mouse Down
        • Left Mouse Up
        • Right Mouse Down
        • Right Mouse Up
        • Set Mouse Target Filter
      • Keyboard
        • Key Down
        • Key Up
      • GUI
        • GUI Mouse Enter
        • GUI Mouse Leave
        • GUI Mouse Moved
        • GUI Mouse Wheel Up
        • GUI Mouse Wheel Down
      • GUI Buttons
        • GUI Left Click
        • GUI Left Mouse Down
        • GUI Left Mouse Up
        • GUI Right Click
        • GUI Right Mouse Down
        • GUI Right Mouse Up
      • Text Box
        • Text Box Focused
        • Text Box Focus Lost
    • Miscellaneous
      • Variables
        • Set Variable
        • Print
        • Warn
        • If
        • Type Of
      • Loops
        • For Loop
        • While Loop
        • Loop Through Table
        • Loop Through Children
        • Loop Through Descendants
        • Break Loop
        • Continue Loop
      • Functions
        • Define Function
        • Function Return
        • Execute Function
      • Run
        • Wait
        • Do Not Run
        • Execute Block
        • Render Stepped
      • Run
  • Objects
    • Objects Index
    • Instances
      • Accoutrement
      • Animation
      • Backpack
      • BillboardGui
      • BindableEvent
      • BindableFunction
      • BlockMesh
      • BodyAngularVelocity
      • BodyColors
      • BodyForce
      • BodyGyro
      • BodyPosition
      • BodyThrust
      • BoolValue
      • BrickColorValue
      • Decal
      • Dialog
      • Explosion
      • Fire
      • Smoke
      • SpawnLocation
      • SpecialMesh
      • Team
      • Texture
      • Tool
      • Truss
      • Weld
    • Services
      • Workspace
      • Players
      • Lighting
      • StarterGui
      • StarterPack
      • Debris
      • Teams
      • Soundscape
  • Guides
    • Guides Index
    • Simple Guides
      • Intro to Loops
      • How to make a Debounce Script
Powered by GitBook
On this page
  • Loops
  • Introduction
Edit on GitHub
  1. Guides
  2. Simple Guides

Intro to Loops

PreviousSimple GuidesNextHow to make a Debounce Script

Last updated 1 year ago

Also refer to ,

Loops

Introduction

Let's say you need to automate something, like giving weapons to a team of players. Loops can automate tasks that could usually take longer when drawn out. You can use loops for many different things, such as rounds for a game, timers, and much more.

For this guide, I'll be showing examples of all the different loops, and how you can use them.

For Loops

Like I mentioned before, we can use the For Loop block for timers.

We'll start by counting down by 100. Set the Initial value to 100, set the Increment value to -1, and set the Maximum value to 0. This makes it so you start at 100 and begin adding -1 (subtracting 1) to 100. Set the Place output (what number the loop is currently at) to what ever name you want. I'll set it to "Place".

Now, connect a wait block and keep the Time value to it's default. Then connect a print block and set the text as a variable, and type your variable name.

Good job! Now you've made an easy timer.

Other examples where you can use the For Loop block for are:

  • Typewriter text

  • Stopwatch

  • Moving multiple parts at once

While Loops

Well, what if you need something that lasts infinitely? A while loop lasts forever, which can be pretty useful in some cases.

This time, we'll be making a health monitor. Make sure to insert a local script instead of a regular one.

First, get your player by adding a Set Variable block to game.Players.LocalPlayer. I'll name the variable to "Player". Next, insert your While Loop block, you don't need to change any properties because nil already equals nil. Connect a wait block to the loop and set the time to 0 seconds. DO NOT FORGET TO ADD THIS BLOCK OR ELSE YOUR GAME WILL CRASH. Then, get your health from the character. Connect a Get Object Property block. Set the object to Player.Character.Humanoid and set the property to Health. You can name the health variable anything you want, but I'll set it to "Health". Next, print out the Health variable and you're done!

Nice! Now you have a basic health monitor.

For Loop
Loop Through Table
image
image
image