I am still a learning developer, and I am trying to teach myself how to make explosive projectiles. I don’t know how to script these things, whether I use scripts to handle the movement or use VectorForces or something. I want these projectiles to explode on impact, and I also want them to unanchor any parts they hit. I have absolute zero clue on where to start with this, but I have a general idea of Roblox coding. Thanks in advance!
To make an explosion effect, there is an instance called explosion, which you can create via script. Once the explosion is created, it will immediately give the explosion effect (I believe). So let’s say your projectile hit something using the Touched event. If the projectile hits anything, it will create the explosion effect.
Here is an example:
Projectile.Touched:Connect(function(hit) -- hit is what touched the projectile
if hit ~= nil then
local explosion = Instance.new("Explosion")
explosion.Visible = true
explosion.Parent = Projectile
end
end)
I suggest you read about the explosion instance as well as its properties, functions, and events to understand more about how explosions work.
To add to this, I would personally use GetPartsInPart or some other version of OverlapParams as those are much more accurate. Though a touch event may be fine if accuracy isn’t a big deal.
Also, just as a side note, you can just do:
if hit then
rather than:
if hit ~= nil
https://developer.roblox.com/en-us/api-reference/event/Explosion/Hit
Additionally, explosion instances have a ‘Hit’ signal/event that is fired whenever the explosion comes into contact with a part, any callback functions connected to it receive two arguments when it is fired, the hit part & the hit distance, the former is useful for identifying parts that belong to a character model (a model that contains a humanoid) and the latter is useful for determining how much damage to apply.