How to do destruction in Roblox – Lua lesson for kids

In this tutorial we will show you how to create destructible blocks in Roblox. Let's add simple objects to the map and write programs for them in Lua.

Roblox Studio is a great engine for creating your first 3D games. Here, children from 9-10 years old can learn to model objects and program in the simple Lua language. In the process, you can learn how to create both small games and full-fledged projects with many different functions.

In this tutorial, we will share two methods of creating destruction and explain which Lua script is suitable for each of them. The resulting elements can be added to the destruction simulator in Roblox or your game of another genre.

Material prepared by a programming school for children Pixel. At the end of the article you can find a video that clearly shows all the actions from the tutorial.

First version of a destructible block

Destructible platforms will add a lot of dynamics to your map in Roblox, let's look at the different ways to create them.

The easiest way to construct a destructible object is to use the :Destroy() method. To do this, create a block on the map and add a script to it:

Creating an object on the map

Creating an object on the map

Adding a script to an object

Adding a script to an object

Next, let's write the following script:

Script for destruction

Script for destruction

In this script, we will use an animation that will move our platform up, after which it will disappear.

Let's look at the destruction code in Roblox:

The first two lines define the variables. Variable block sets the parent object to which the script is attached. Variable twinService gets the service used to create the animation of the block moving.

Function onTouched(hit) called when the player touches a block. If the player has an object Humanoid in the parent element, then the object receives the property Anchored = falsewhich allows him to move. The animation parameters are then determined, including duration, style and direction, and the final position of the model after animation. And the animation is created tween.

  • Enum.EasingStyle.Linear — animation style. In this case, we use a linear animation style, which means that our element will move at a constant speed.

  • Enum.EasingDirection.InOut — animation direction. In our case we use InOutthis means that the block will move in opposite directions as the animation plays, moving up and then down.

After the animation is created, tween:Play() reproduces it.

Function wait(1) waits one second for the animation to end and then destroys the block using the method block:Destroy().

Finally, block.Touched:Connect(onTouched) connects function onTouched() with a block touch event so that it is called every time the player touches it.

As a result, when it comes into contact with a player, the block will move upward and then disappear. This type of destruction is well suited for a parkour map.

Second version of the destructible block

Now we will create a more realistic effect of the destruction of our block, in which it will not only disappear, but also leave behind debris.

Let's create a Part on the map and add a script to it:

Creating a second object

Creating a second object

Adding a script

Adding a script

Next, let's write the following script:

Code for destruction

Code for destruction

We explain the destruction script in Roblox:

At the beginning of the code, a block object is defined, which is the parent object of the script, that is, the block itself.

Then when the event occurs Touched on the block, the function is called onTouchedwhich takes an argument hit. Variable hit contains information about the object that came into contact with the block.

Next, the script checks whether hit an object containing Humanoidusing the method FindFirstChildOfClass. If hit contains Humanoidthen the action of destroying the block and creating debris is performed.

The method used to destroy our platform is BreakJointswhich destroys all connections between the block and its neighboring objects, allowing the block to move freely.

Then a cycle occurs that repeats 10 times and creates 10 new debris. A new object is created for each block CornerWedgePart with randomly determined properties of size, rotation, color and material. Each element is placed in a random location around the original block using the property CFrame. CFrame is a coordinate system that stores information about the position and orientation of an object in 3D space, with its help we can set the position relative to the coordinates of the main block by adding a random offset.

At the end, the script deletes the original block using the method Destroy.

Thus, when a player or object touches a block, it is destroyed and several new blocks with different properties appear in its place, creating a destruction effect.

Covers after the cube is destroyed

Covers after the cube is destroyed

This script works great on MeshPart:

Video: Creating Destruction in Roblox Studio


In Roblox Studio you can create games in various genres: runners, horror, RPGs, various simulators, etc. If you want to go deeper into game development on this engine, learn how to create individual functions and details (animation, teleport, NPC, store, inventory and much more), as well as full-fledged projects that users from all over the world can play, then watch the cycles of our free lessons on Rutube channel.

And if you want to take Roblox training under the guidance of a teacher, check out the online courses on modeling And programming from Pixel School.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *