How To Make A BATTLEGROUNDS GAME In Roblox Studio 2024 — Transcript

Learn how to create a battlegrounds game in Roblox Studio 2024 with a simple combat system including punching and blocking.

Key Takeaways

  • Roblox Studio allows for detailed combat system creation using animations and scripting.
  • Animations must be published with correct priority and saved IDs for use in scripts.
  • RemoteEvents and RemoteFunctions facilitate communication between client and server for multiplayer combat.
  • Organizing scripts and assets in folders improves project structure and maintainability.
  • UserInputService is essential for detecting player actions like punching and blocking.

Summary

  • Introduction to a new series on making a battlegrounds game in Roblox Studio.
  • Tutorial on creating a simple combat system with punch and block mechanics.
  • Instructions on publishing the game and setting avatar type to R6.
  • Guide on creating and publishing animations for blocking and punching.
  • Setting up RemoteEvents and RemoteFunctions in ReplicatedStorage for attacks.
  • Creating scripts for data handling, server attack handling, and client-side attack logic.
  • Importing a custom model and UI from the Toolbox via a provided link.
  • Implementing player values and character selection system.
  • Using UserInputService to handle player inputs for combat actions.
  • Debugging and testing the combat system with animations and hitboxes.

Full Transcript — Download SRT & Markdown

00:00
Speaker A
Hello everyone, and welcome back to a new series. In this series, I'm going to be showing you how to make a battlegrounds game in Roblox. In this video, I'm going to be showing you how to make a simple
00:08
Speaker A
combat system where you can punch other players, and you will also be able to block attacks. Also, this series will be finished in the next couple of weeks.
00:18
Speaker A
Before this video starts, if you guys want to support me and want to have access to all of my project files, including the one you're watching right now, they will all be available on my Patreon in the $10 tier.
00:29
Speaker A
Okay, so the first thing we need to do is to publish our game. So, we're going to go to the Home tab over here and go to Game Settings and press Save to Roblox. And now we'll call our game
00:39
Speaker A
Battlegrounds Tutorial. And I'm going to press Save. You can name it anything you want. And now it will reload the game. Okay, the next thing we need to do is to go to the Game Settings again and set our game to R
00:54
Speaker A
six. So, we're going to go to the Avatar tab and set the avatar type to R6.
00:58
Speaker A
Now, press Save and press Yes. And now our game is switched to R6. The next thing we need to do is make some animations. So, you're going to go to the Avatar tab, go to Rig Builder, and
01:09
Speaker A
press Block Avatar and make sure that it's R6. And now, it will load a rig. And this is the rig that we're going to be animating. So, open up the Animation Editor. And by the way, I'm not an
01:20
Speaker A
animator, so I got some animations from elsewhere. And I'm going to show you how to make your animations, just how to set them up. But you will have to make your own animations or you can find some
01:30
Speaker A
in the Toolbox. Okay. So you're going to go and make sure that whenever you make an animation, let's say we want to make—we need to actually, no, we need to start with a block animation. So the
01:42
Speaker A
block animation will be something like this. Your hands will be up. And I won't make a new block animation because I already have one. And this is just like for testing purposes right now, just to show you how it's done. And you just
01:56
Speaker A
make sure to press Loop in here and make sure to go to these three buttons over here and go to Set Animation Priority and press Action. Now you can go to the three dots again, Publish to
02:08
Speaker A
Roblox, and you can call it whatever you want. You're going to call it, let's say, you want to call this Block.
02:15
Speaker A
Now make sure to check Delete Local Instances. This is not, um, this is optional. So, but I would recommend checking it. And now when you press Save, you will see that it gives us an ID. We can copy this ID and save it. So
02:30
Speaker A
press this button over here and it will copy that ID. And now we want to open up your Notepad or save this wherever you want. I'm going to save it in a script. I'm going to create a new
02:40
Speaker A
script. And I'm just going to make it all commented like this. And we can have our IDs in here. So we're going to call it Block ID.
02:51
Speaker A
And just do that. Okay. So now you can make your other animations. We're going to create a punch animation. So go to New, create new, and the punch animation should not be looped. So make sure it's not looped,
03:05
Speaker A
but the animation priority should be set to Action. So the punch animation, let's say this is our punch punch animation. As I said, I'm not going to make one right now because I already have one made. Okay. So then you
03:16
Speaker A
just go here and press Publish to Roblox. Now, I would recommend that you make a right punch animation, left punch animation, then another one. You can have as many as you want. Those will be played consecutively after each click.
03:29
Speaker A
So, you can have as many as you want. Or an easier way to do the animations.
03:34
Speaker A
Well, basically, we're not going to be making them, but you can just go to the Toolbox and look up combat animations.
03:42
Speaker A
And then you can just drag in any one of these. Just put them here. And then when you go to the Animation Editor now and you click on the model, it will open up this and press Okay. And now you
03:54
Speaker A
can see that we have all of these animation clips. Now you can go here on these three dots and go to Load. And now you can choose any of these. You can go to, let's just say, Idle. Let's just—I
04:05
Speaker A
want this idle animation. You go to these three dots, Publish to Roblox. Just make sure that animation priority is set to Action and Publish to Roblox.
04:14
Speaker A
And you just make sure to save your ID. So make sure that you publish your own animations. Okay. So I already have my animations, as I said. Okay. So now we need to set up our game. We need to go
04:25
Speaker A
to ReplicatedStorage, add a folder, and we're going to call it Events. Now in this Events folder, we're going to have three events. We're going to add a RemoteEvent. And this one will be called Block.
04:39
Speaker A
Duplicate it. And this one will be called ClickAttack. And now we will have another one, but this one is going to be a RemoteFunction, not a RemoteEvent. Make sure that it's a RemoteFunction. And we're
04:52
Speaker A
going to call it SpecialAttack. This one will be used later in the next part.
04:57
Speaker A
But I'll show you what it's going to be used for. And now the next thing we need to do is go to ServerScriptService and we're going to have a script. We're going to call this
05:06
Speaker A
script DataHandler. And we're going to add another script. And this time it's going to be called ServerAttackHandler.
05:16
Speaker A
ServerAttackHandler. Add a ModuleScript. And this one is going to be called AttackHitboxes.
05:29
Speaker A
Okay. So now we're going to go to StarterPlayer, StarterCharacterScripts. And we're going to add a folder. Now this folder is going to be called CharacterAttacks and the next one add another folder and this one is going to be called DefaultAttacks. Now we will go and add a LocalScript to this. Now we're going to call this script ClickAttacks.
05:46
Speaker A
Now we'll close all these scripts by right-clicking on one and pressing Close All Scripts. And now you will get a model that I made. I published it. You will have to get it from the
05:59
Speaker A
link in the description. And you will go to the Toolbox and drag it. Now I'll show you how to do that. Okay. So after clicking the link in the description, it should take you to this. And you should
06:12
Speaker A
just press Get. I don't know what it's going to say. It's probably going to be Get. And then you will get this item and go back to Studio. And now in Studio, we'll go to Home, Toolbox, and
06:22
Speaker A
go to Inventory. And then just drag in your model. Now I need to wait for this to load and press Battlegrounds Game UI and press Okay.
06:32
Speaker A
And now we'll get this main GUI and put it in the StarterGui. And this is how it looks. I'm going to play to show you what it is. It's just this simple UI with a toolbar and a character tab where
06:43
Speaker A
you can select characters. And now we're going to stop the game and move on to the next step. So we're going to go here, enter the DataHandler script, and we're going to need to get the player
06:55
Speaker A
service. So local players equals game:GetService("Players"). And now we need to do players.PlayerAdded:Connect(function(player) and that will take the player. And what we need to do is create a folder inside of here
07:07
Speaker A
inside of this script. And we'll call it, um, I think it should be called PlayerValues.
07:21
Speaker A
And we're going to have a folder inside of it, and it's going to be called Values, and we're going to have a StringValue inside of it and it's going to be called Character and we will choose Hunter.
07:29
Speaker A
Okay. So now what we need to do is loop through that folder. So we're going to do for _, v in ipairs(playerValues:GetChildren()) do and we're going to do v:Clone().Parent = player. Now, if you play the game, we
07:43
Speaker A
should have a Values folder in our player. And as you can see, we have Values and Character. Okay. So, the next thing we need to do is to enter the ClientAttacks. Now, in here, what we're going to do is we're going to need to
07:58
Speaker A
get some services. So, local UserInputService equals game:GetService("UserInputService"). Now, we need
08:13
Speaker A
get some services. So, local user input service equals game call get service user input service. Now, we need replicated storage. replicated storage equals game col get service replicated storage and now local run service equals game col get service run service.
08:32
Speaker A
Okay, now we need to get the events folder that we have in replicated storage in here. So we're going to reference it by doing local events equals replicated storage wait for child event. We are using wait for child
08:44
Speaker A
because we are in the client and now we need to get the character. So local character the character should be equal to script.parent.p parent because if we play the game the scripts are going to be inside our character.
08:58
Speaker A
So the character is going to be script.parent.parent and now we need to do user input service user input service.input began call connect function and that's going to take the input and the game processed event.
09:14
Speaker A
Now we need to do user input service.input ended comma connect function and we're going to do input game processed event and now we're going to go back here and we're going to have a variable that we're going to use later
09:29
Speaker A
called is blocking and that is going to be set to false. Now we will go back here in the input began function and we're going to do if game processed event then return. Now uh this will anything that that's going to
09:44
Speaker A
be written in here will run every time the uh any sort of input is um is done and the game processed event will pretty much uh stop us from so these three lines of codes of code will pretty much
09:56
Speaker A
stop us from um calling this when we are typing something in the chat or something like that. Okay. So what we need to do is do if input do user input type equals equals enm do user input type dot mouse button
10:13
Speaker A
one then and we're going to do event dot click attack confire server and we're going to send the character humanoid group C frame.
10:28
Speaker A
Okay. So now we're going to do in here and not is blocking. So if we are not blocking then we're going to call this actually now that I think about it we don't really need to uh send the
10:41
Speaker A
character C frame just do call fire server and now go down here and do if input dokey code equals equals inkeycode dot f then just do is blocking equals true and events dobblock commire server and we're going to send true
11:02
Speaker A
okay And now do the exact same thing here. I'm going to do just copy this.
11:06
Speaker A
And this time it's going to be false. And in here we're also going to send false. Okay. So we also need uh this game process event thing in here. Okay.
11:18
Speaker A
So enter uh uh click server attack handler. And what we need to do in this script is we're going to have a folder, a couple of folders actually, not just one. The first one is going to be called
11:32
Speaker A
animations. And the second one is going to be called characters. And the third one is going to be called punch animation cycle.
11:46
Speaker A
And uh the next thing we need to do is go inside of the characters and we're going to have a temporary character called the hunter.
11:54
Speaker A
Okay. So, in this uh hunter folder, we're going to have a mod script, and we're going to call it one. I'll just leave it like this. We're not going to touch it yet. You can just go to server
12:04
Speaker A
attack handler. And now, what I need you to do is go to the animations folder and add an animation and call it block.
12:13
Speaker A
Now, you're going to set the animation ID to your block animation ID. Now, I'm going to go get my block animation ID.
12:20
Speaker A
It's uh this. And now we're going to go to the punch animation cycle and add animations. And uh the first one is going to be the first punch that you want the player to be able to throw. Now I'm going to call
12:34
Speaker A
it one. Make sure that they're named like this. One, two, three, four in order. Okay. So, uh this is going to be one and I'm going to set its ID to the one that I have to a right punch that I
12:46
Speaker A
have. And then I'm going to make another one is going to be two. And it's going to be set to my left punch. And now you can just keep on setting them. But what I'm going to do is I'm just going to copy
12:57
Speaker A
them from another place because I already have them made. And I'm just going to paste them here. Okay. The next thing we need to do is to go to the player values in here. And inside of this folder, we're going to add an int
13:10
Speaker A
value. And we're going to call it uh punch combo. Or maybe punch. Yeah, punch combo.
13:19
Speaker A
Okay. So now we're going to go back to our uh server attack handler and we're going to get replicated storage. So local replicated storage equals game get service replicated storage. Now we need to get local players equals game get
13:35
Speaker A
service players. Now we're going to do local events equals replicated storage.event. Now local attack hitboxes equals require script.parent parent dot uh script.parent attack hitboxes. And now we need to do local click debounces.
13:54
Speaker A
Click attack debounces. And we're going to set it to an empty table. Now what we're going to do is we're going to do events dot click attack dot on server events connect function. And this is going to take the player
14:09
Speaker A
and whenever the click attack is called from the client, this is going to run in the server. And what we need to do is a couple of checks. Uh I'm going to copy them from my other place and paste them
14:20
Speaker A
here. This is what you need to do. We're going to get the character. Then we're going to check the character is nothing.
14:26
Speaker A
Then we're just going to stop everything. So return this. This here will not run. If this runs, if return runs and then we're going to get the humanoid. If the humanoid is not there, then we return again. And if the health
14:37
Speaker A
is less is less or equal to zero, then we return. And if there is a player in the debounces table, then we will return. So just copy all of these and you uh type that in your game. Okay. So
14:51
Speaker A
the next thing we need to do is do click attack debounces square brackets player and we're going to set that to true. Now we need to choose we need to actually get the punch combo value. Punch combo equals player dot values.punch
15:07
Speaker A
combo. And now we need to do uh we need to get the animation that we want to load. So local animation equals script punch cycle animations square brackets two string and we're going to do punch combo do value.
15:27
Speaker A
Now we need to load it. So local loaded punch animation is going to be uh humanoid animator on load animation and that will take uh the animation that we just uh got. Now we're going to do a loaded punch
15:46
Speaker A
animation col. And in here down here what we need to do is uh check if the combos value is greater than how many animations we have. So if punch combo do value is greater or equal to uh however many
16:04
Speaker A
punch animations we have in this folder and the way we get that is by doing hashtag uh script.punch punch animation cycle get children and that will this will return how many children are in this folder and then we're going to do
16:16
Speaker A
then and we're going to do punch combo uh equals 1 and we're going to do else and we're going to do uh actually sorry I need to do punch combo dov value equals 1 and uh else punch combo do
16:30
Speaker A
value plus equals 1. Now we're going to go down here and do attack hitboxes.
16:37
Speaker A
Actually no we're not going to do that yet. Just do taskweight. Uh, actually, no, don't do that. Just do um, okay, I'm gonna do task.weight loaded animation.length plus 0.1. And then we're going to check if the player is still in the debounce
16:57
Speaker A
table. So, if click attack debounces player, then click debounces square brackets player equals no. So, we just remove him from that table. Okay. So now I need to make sure that this works, but it's not going to work yet. It's not
17:09
Speaker A
going to deal any damage, but we're just going to play the game to see if it plays the animation itself. Okay, so I am getting an error and that is because punch combo is not set to one by
17:19
Speaker A
default. It should be it should always set be set to one. And now if you play the game, I think it should work.
17:27
Speaker A
Okay, so now as you can see, we have animations and they play when we click.
17:32
Speaker A
And now we need to make it so that when there is a player nearby, we damage them. So in order to do that, we need to enter our attack hitboxes script. And let me just enter it from my other place
17:44
Speaker A
or where I already prepared it. And we need to have a function. So function module dot create hitbox.
17:54
Speaker A
And that create hitbox function will take the character of the player character and the hitbox size which is going to be a vector 3 the damage and and whether that attack is blockable or not.
18:13
Speaker A
So what we're going to do now is inside of this uh function we need to create a new part which is going to be our hitbox. So, local hitbox equals instance dot new uh sorry dot new part. And we're
18:24
Speaker A
going to do hitbox.transparency equals uh let's just do 0.5 for now. Hitbox dot uh brick color equals brick color red. And I'm going to do hitbox collide equals false. Hitbox dot anchored equals true. And we're going to do hitbox
18:44
Speaker A
size equals hitbox size. And now we're going to do hitbox C frame equals character do humanoid root part C frame. And we're going to multiply that by C frame new.
19:01
Speaker A
And we're going to do 0 comma 0 comma minus. Let's just do minus 4. And now I'm going to do hitbox parent equals workspace. Now what we're going to do is get what what parts are inside of this hitbox. So local parts in
19:18
Speaker A
hitbox equals workspace call get parts in part and you just type in your hitbox. So just do hitbox and this will return what parts are are currently touching that uh hitbox. And we're going to have a debounces table
19:34
Speaker A
just like we did on the other script. And this time we're going to do for underscore comma v in parts in hitbox do. Uh actually I need to do uh oh never mind do and what we need to do is get v
19:48
Speaker A
humanoid. So local humanoid equals script equals v dot parent find humanoid or v.p parent.p parent find first child humanoid.
19:59
Speaker A
Okay. Now what we need to do is check if humanoid and humanoid. Character. So if the humanoid that we we are trying to damage and is in the hit box is not the actual player who punched then then we're going to do and not uh
20:18
Speaker A
debounces square brackets humanoid. So if the humanoid is not in that debounce table then and what we need to do is debouncees humanoid equals true and if blockable then and if it's blockable then we're going to check if not humanoid. So the
20:40
Speaker A
character find first child blocking then then we're going to do humanoid.alth equals humanoid health. Actually, we need to do math.max. Then we're going to do uh zero, comma, and we're going to do humanoid.alth uh minus damage.
21:00
Speaker A
Now, if you're wondering what math domax is, so you give it any amount of numbers. Let's say we give it three, five, and six. It will return six. It will return the biggest number. So, the reason why we are doing this is just in
21:14
Speaker A
case this is less than zero, then the health will be set to zero. Okay? Okay, so else then you just copy this line of code over here that I just explained and paste it there. Okay, now we need to do
21:25
Speaker A
task delay and we're going to do 0.3 function and we're going to do a hitbox on destroy.
21:34
Speaker A
Okay, now we need to create that hitbox. So I need to call this function. So what I'm going to do is in here I'm going to do u attack hitboxes create hitbox and that will take the character and the uh size of the hitbox. So vector
21:53
Speaker A
3 new I'm going to set it to 9a 9 and then I will send um the damage that we want it to deal. So, I want it to deal uh 25 or 10. And is it blockable?
22:08
Speaker A
Yes. Okay. So, now if you play the game, I think it should work hopefully.
22:17
Speaker A
And as you can see, when we punch, it does create the hit box. And as you can see, there is a little delay, but that's uh that's not really a big problem. Uh but yeah, what we're going to do now is
22:28
Speaker A
uh let's say you want this to only happen when you are uh when the player reaches a certain key frame in the animation. So what I'm going to do is I'm going to load the animation that I have. So uh I'm going to do a block
22:43
Speaker A
avatar and I will load it animation editor. Why can't I Why can't I open it?
22:50
Speaker A
Okay. Okay. So, you need to go to the animation editor and go to uh these three dots over here, import from Roblox. And then you just uh choose a specific one. So, I'm going to choose hit one. And every time we reach here,
23:05
Speaker A
what I want to do is right click on here and add animation event here. So, you just need to select this, right click and add animation event. And then you name it hit. Uh it will give you a uh
23:18
Speaker A
place where to add an event. But I've already created mine, so I'm just going to save. I'm just going to press cancel because I already have mine. But you need to press save and then go here again and publish to Roblox. And this
23:30
Speaker A
time we're going to go and overwrite an existing asset and hit one. And then you just press save.
23:41
Speaker A
Okay. Now that that's done, we're going to go back to our uh attack handler script. So what we need to do here is before we create the hitbox what we're going to do is uh loaded punch animation dot and just do no not dot sorry it's
23:56
Speaker A
colon colon get marker reach signal and just type in hit colon connect function and then you just uh do this.
24:09
Speaker A
Okay, so we're going to play the game now and see if this works. And as you can see now the uh hit box only creates itself when we reach that specific uh key frame. Okay. So now I'm going to test this on a rig. I'm going
24:25
Speaker A
to put one here, one here, one here, and I'm going to play the game and see if this works. Okay, so it is now loaded.
24:32
Speaker A
I'm going to uh click and the hitbox does show up. Okay, and I'm going to press this. And as you can see, it deals damage to the character. Now, I'm going to make the hitbox invisible because we don't really need it. And I'm going to
24:47
Speaker A
go here. Where is it? Where is it? Uh, attack hit boxes. Okay. Transparency is going to be one. And what we're going to do now is we're going to do blocking really quickly. So, I'm going to go to
24:58
Speaker A
the server attack handler. And what we need to do now is go and do events. Oh, sorry.
25:06
Speaker A
Events.blog block on server event connect function and that will take the player and the u value. So true or false. Now you will just have to copy that from the this from the top script here and paste it in there. And now you need
25:25
Speaker A
to check if not value then so if uh that value is equal equal to false then we just get every single loaded animation from the humanoid. So you just do local loaded animations equals humanoid animator col gets plain animation
25:40
Speaker A
tracks. Now we loop through those animations and we check if the name equals equals block. So for underscore comma v and loaded animations if name equals equals block then we just stop that animation and we do if character
25:53
Speaker A
confine first child block in then character confine first child block and col destroy. And we'll see why that is because we're going to add a nails and we're going to load a block animation.
26:03
Speaker A
Now the block animation is the one that we have over here in the animations folder. So we load that one and then we play it. So block animation column play and then we'll create a string value. So local blocking equals instance new
26:18
Speaker A
string value. We're going to set its name to blocking and then we're going to set its parent to the character. Now if you play the game, we're going to wait for this to load of course again and it
26:30
Speaker A
takes way too long. And as you can see when we hold down F, we are able to block. And if we go to our character, we have a uh blocking thing in our a blocking value in our character. And we can of course punch.
26:45
Speaker A
And let's just make sure that this works. And as you can see, it does deal damage.
26:50
Speaker A
And it's actually pretty cool. I really like it. And what I'm going to do now is actually no, I'm not going to do anything. I think that's going to be it for today's tutorial. If this helped, make sure to subscribe, like the video,
27:01
Speaker A
share it with your friends. I'll see you guys in the next video. Bye.
Topics:Roblox Studiobattlegrounds gamecombat systempunch animationblock animationgame developmentRoblox scriptingRemoteEventUserInputServicegame tutorial

Frequently Asked Questions

How do I publish animations for use in my Roblox game?

You create animations using the Animation Editor, set the animation priority to Action, and then publish them to Roblox. After publishing, copy the animation ID and save it for use in your scripts.

What is the purpose of RemoteEvents and RemoteFunctions in this tutorial?

RemoteEvents and RemoteFunctions are used to handle communication between the client and server, enabling multiplayer features like blocking, clicking attacks, and special attacks in the combat system.

How can I import the custom model and UI used in this tutorial?

You can get the model from the link provided in the video description, then use the Toolbox's Inventory tab in Roblox Studio to drag and insert the model and UI into your game.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →