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
  • Introduction
  • How to make it
  • How does it work?
Edit on GitHub
  1. Guides
  2. Simple Guides

How to make a Debounce Script

PreviousIntro to Loops

Last updated 1 year ago

Introduction

You make a simple script that when you touch, it gives you a tool!

You test it out, but the script rapidly and spontaneously giving tools. That's because you don't have a debounce part of your script.

How to make it

To make a debounce script, we need to create a variable. This variable will track when the tool has been touched and on cooldown or not. Then, before the event block, you want to set the variable to false, to first, indicate that the part hasn't been touched when the game loads, and second, to allow the following if statement to work. Just after the event block, add an if statement. Now, we're going to set the first parameter of the if statement to be the variable we just created. The second parameter will be set to false. (Click the dropdown menu, select "Bool" then type in the name of your variable) Next, set the variable back to After, insert your code for whatever you want to do! The next step is to add the actual delay, and to set the variable back to false.

How does it work?

The very first set variable makes it so the cooldown is off when the game first loads. The if statement runs when the event block is fufilled, (ex: once part is touched, when remote event is received, etc.) and if the cooldown is on. If it is on, it prevents the script from continuing further and cause the rapid and spontaneous burst of tools. The wait is to actually add the cooldown part of the script. The final set variable is to turn the cooldown back off.

image