Introduction
Hello developers! This is my first Community Tutorial, so please provide feedback when you finish reading!
Today, I’ll be showing you how to make a basic TNT model using the beloved Proximity Prompt and the Attributes feature.
Creating your model
The first thing we need to do is create a TNT model. I have already created one which I will show you, but feel free to create your own. Creativity is key!
Here is mine, it looks absolutely horrendous but it gets the job done!
Here is how I setup the model:
Once you have created your model, create the following attributes in your model’s properties.
- BlastPressure (number value)
- BlastRadius (number value)
- DestroyJointRadiusPercent (number value)
- ExplosionType (string value)
Set these properties to your liking, however I will be setting them to the default values of the regular “Explosion” instance.
Scripting
Here is the fun part, the scripting!
So, first things first, we need to create our variables. Here is how we are going to do it:
-- Variables
local TNT = script.Parent
local TNTBase = TNT.TNTBase
local Fuse = TNT.Fuse
-- ProximityPrompt variable
local ProximityPrompt = TNTBase.ProximityPrompt
Name these according to your model, of course.
Next, we need to get the attributes that we created previously. Simply type:
-- Attribute variables
local BlastPressure = TNT:GetAttribute("BlastPressure")
local BlastRadius = TNT:GetAttribute("BlastRaidus")
local DestroyJointRadiusPercent = TNT:GetAttribute("DestroyJointRadiusPercent")
local ExplosionType = TNT:GetAttribute("ExplosionType")
Now, we need to setup our ProximityPrompt.Activated
function. Here is how we do this:
-- Main function
ProximityPrompt.Triggered:Connect(function()
end)
What we are saying here is when this ProximityPrompt
which we previously defined is activated, then do stuff!
Here is the stuff we will make it do. Type out this:
local Explosion = Instance.new("Explosion")
Explosion.BlastPressure = BlastPressure
Explosion.BlastRadius = BlastRadius
Explosion.DestroyJointRadiusPercent = DestroyJointRadiusPercent
Explosion.ExplosionType = ExplosionType
Explosion.Parent = TNT
Explosion.Position = TNTBase.Position
Essentially what is going on is we are creating a new Explosion
object, setting its BlastPressure
, BlastRadius
, DestroyJointRadiusPercent
, ExplosionType
, its Parent
and its Position
.
Make sure you change all of these variables to match your model!
Conclusion
Annnnnnnnnd that’s the end of the tutorial, if you found it helpful, consider liking the post! Now, I know there is many flaws with this like there being no cooldown but this is a basic script and it’s my first tutorial, so please be gentle. Also, no credit is needed whatsoever if you use my model in your game.
Model: tnt.rbxm (4.7 KB)
Have a good rest of your evening, developers!