[Part1] Easy Roblox Combat System for Beginners | (Basic Roblox Services, Hitbox Detection)

[Part1] Easy Roblox Combat System for Beginners | (Basic Roblox Services, Hitbox Detection)

How to Create a Combat System in Roblox

Introduction to Roblox Studio

  • The video serves as a tutorial on creating a combat system in Roblox, with an expected duration of around 40 minutes.
  • It introduces the object-oriented nature of Roblox and how it operates within its studio environment.

Understanding Character Structure

  • The starter character is discussed, highlighting that the workspace contains an object called "me," which represents the player's character.
  • A folder named "core" is created for organizational purposes, emphasizing that anything placed in this folder will replicate to the character.

Scripting Basics

  • The importance of comments in scripts is explained; two dashes create comments for clarity and documentation.
  • Emphasis on defining variables and using run service events like render stepped to detect player actions continuously.

Input Handling

  • Documentation's usefulness is highlighted, particularly for understanding methods and events within scripting.
  • The difference between events (with periods following their calls) and methods (using double colons) is clarified.

Implementing Mouse Input

  • Using run service allows detection of whether the left mouse button is held down during gameplay.
  • User input service is introduced as essential for checking mouse button states, demonstrating how to print messages based on user interactions.

Managing Remote Events

  • Discussion about replicated storage emphasizes organization and referencing remotes effectively within scripts.
  • Explanation of wait for child versus find first child, detailing how yielding affects script execution timing.

This structured approach provides a comprehensive overview while allowing easy navigation through key concepts discussed in the video.

Understanding Remote Events in Roblox

Replicated Storage and Client Communication

  • The importance of waiting for child remotes in replicated storage is highlighted, as clients do not load all elements immediately. This ensures stability when adding new clients.
  • A new remote event called "attack" is created to facilitate communication from the client to the server, emphasizing the role of remote events in Roblox development.

Script Organization and Accessing Remotes

  • A script named "comt system" is introduced, showcasing organizational preferences by referencing the remotes folder within replicated storage for better code clarity.
  • The server's ability to instantly load all game elements allows developers to use dot notation for accessing remotes without encountering errors.

Event Handling and Function Connections

  • The OnServerEvent method is explained, which triggers a script when FireServer is called from a local script. Documentation on this method is available for reference.
  • Emphasis on connecting functions correctly with player parameters and additional arguments using tables instead of directly including player data.

Character Checks and Humanoid Properties

  • A check for the player's character existence is implemented to prevent issues if the character does not exist at runtime.
  • The humanoid property of characters is explored, noting that it contains essential properties but may require annotation for full functionality.

String Concatenation Techniques

  • An explanation of string concatenation methods in print statements highlights how commas add spaces between strings while dot notation requires manual spacing.
  • A demonstration of how to manage attack prints effectively includes implementing a debounce mechanism to prevent excessive server spam during attacks.

Implementing Attack Logic with Debounce Mechanism

  • To avoid spamming attack messages, a check for an "attacking" instance within the character structure is proposed, leading to creating an instance called "attacking" as part of this logic.

Object Replication and Instance Management in Roblox

Understanding Object Creation

  • The process of creating new instances in Roblox is initiated with instance.new, which allows for the creation of various objects, such as parts.
  • A folder can inherit properties from an instance, allowing it to be named (e.g., "attacking") and parented to a character, which is essential for script functionality.

Variable Names vs. Instance Names

  • It's crucial to differentiate between variable names used in scripts and the actual names of instances being created; changing these incorrectly can break the script's functionality.
  • If an instance like "attacking" is not properly referenced or destroyed after use, it can lead to issues where the script fails after one attack.

Utilizing Debris Service

  • The Debris service allows for temporary destruction of instances by using debris:addItem, which removes an object after a specified time (e.g., 0.5 seconds).
  • Implementing a cooldown period between attacks helps manage gameplay pacing and prevents spamming actions.

Script Execution Order

  • Roblox executes scripts sequentially from top to bottom; thus, any dependencies must be declared after their respective instances are created.
  • Misplacing code that relies on previously defined variables can lead to errors due to the order of execution.

Creating Hitboxes in Roblox

Designing Hitboxes

  • To create hitboxes, start by inserting a part into the game world and positioning it relative to a character model.
  • Holding control while resizing parts allows for simultaneous adjustments along multiple axes, aiding in precise hitbox design.

Configuring Hitbox Properties

  • Key properties such as CanCollide and Massless should be set appropriately; disabling collision ensures that characters do not physically interact with hitboxes during gameplay.
  • Transparency settings allow developers to make hitboxes invisible while still functional for detection purposes.

Importance of Replicated Storage

  • Replicated Storage serves as a shared space where both server and client can access necessary assets; placing items here ensures they are available across different game contexts.
  • Cloning templates from Replicated Storage enables dynamic creation of hitboxes during gameplay without cluttering the workspace with unused objects.

Welding and Hitbox Detection in Roblox

Understanding Welds and Character Parts

  • A local weld is created using instance.new("Weld"), which connects the character's humanoid root part to other parts, effectively "gluing" them together.
  • The weld must be parented correctly; otherwise, it will not function as intended. It's crucial to remember this step for successful implementation.
  • To manage hitboxes, a delay is introduced before destroying the hitbox clone using debris.addItem(hitboxClone, 0.35) to ensure proper timing during gameplay.

Offsetting Hitboxes

  • The offset for the hitbox is determined by manipulating the axes: X (left/right), Y (up/down), and Z (forward/back). Adjustments are made to position the hitbox slightly in front of the player.
  • Issues arise when collision detection is enabled; turning off certain settings can prevent unwanted interactions with non-target objects.

Introduction to Threading

  • Threading allows multiple functions or scripts to run simultaneously, creating parallel processes that enhance performance and responsiveness in game mechanics.
  • An example illustrates how threads operate independently; even if one thread yields due to waiting for an object, others continue executing without interruption.

Implementing Hitbox Detection

  • A loop checks if the hitbox clone remains parented within workspace while utilizing test.wait instead of wait for better performance during detection.
  • Roblox provides built-in methods like getPartsInPart for detecting objects within a specified area. This method collects parameters necessary for effective hit detection.

Filtering Detected Parts

  • Overlap parameters are set up to exclude specific types of parts from detection, ensuring only relevant targets are identified during gameplay interactions.
  • When hitting a target (like a dummy), detected parts include various body components such as arms and legs. This information helps identify valid targets accurately.

Looping Through Detected Parts

  • A loop iterates through collected parts, checking each part's parentage and searching for humanoids within those parents to determine valid targets.
  • The use of underscores in loops indicates unused indices while focusing on values inside arrays—this approach simplifies data handling in scripting contexts.

Understanding Target Hit Mechanics in Roblox

Setting Up the Target Hit

  • The initial setup involves defining a variable target hit that references the parent of the part being interacted with, which is crucial for identifying the model involved.
  • To manage player interactions, a humanoid object is obtained from target hit, allowing for damage application without needing to search for it explicitly.

Implementing Damage Mechanics

  • The method take damage from the humanoid class is utilized to inflict damage on the target character, demonstrating how to manipulate health within the game environment.
  • A display of health is suggested to provide visual feedback during gameplay, enhancing user experience and understanding of character status.

Managing Hit Frequency

  • To prevent instant kills upon repeated hits, a new variable already hit is introduced. This checks if a target has already been damaged within a certain timeframe.
  • The importance of scoping in Lua programming is highlighted; variables must be defined in appropriate scopes to avoid errors when referencing them later in code execution.

Finalizing Game Mechanics

  • Adding logic to update already hit ensures that characters can only be damaged once per interaction cycle, creating a more balanced gameplay experience.
  • Key takeaways emphasize avoiding copy-pasting code blindly and understanding each line's function—critical for effective game development.

Understanding Scoping and Documentation

  • Scoping rules are explained through an example function. Variables defined inside functions cannot be accessed outside their scope, reinforcing best practices in coding structure.
  • The speaker stresses the importance of utilizing documentation effectively as a resource for recalling methods and understanding their functionalities better.
Video description

Combat Tutorial -- Episode 1 I made this for some of my irl friends, but they wanted me to make it public, so yeah. Complete raw unedited footage on how to script a combat system on ROBLOX STUDIO. A sort-of compilation of mini scripting tutorials in one with a focus on the combat system. UserInputService, RemoteEvent, Client-Server Communication. This is just from my perspective on what I think when I'm scripting. I'M NOT A PRO!! Timestamps: 00:00 Introduction 00:25 Studio Basics & Organization 01:50 Scripting - Using Comments 02:40 Documentation! Your Best Friend 02:50 Input Handling For Combat 06:30 WaitForChild vs FindFirstChild 08:30 RemoteEvents 09:15 Server Side For Combat 14:00 Concatenation 15:00 Server Side For Combat Cont. 20:30 Creating the Hitbox & Studio Controls 21:30 CanCollide & Massless 22:45 ReplicatedStorage & Scripting The Hitbox 27:05 Threading & Task (Poorly Explained Sorry!) 28:40 Hitbox Cont. 35:30 Scoping..? (Roblox Compiler) 37:00 Conclusion & Wrap-up 39:00 Episode 2 Talk #roblox #robloxstudio #scripting #lua #robloxdev #robloxvlog #devlog