Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a part explode on collision?

Asked by
PioIAm 6
3 years ago

I have a script for a long-range attack and I want to make it create an explosion anytime it collides with ANYTHING because right now, it only explodes when players are directly hit, and just phases through everything else.

I’ve searched far and wide and couldn’t seem to find anything that would help me do this, I’ve only seen people explain how to create explosions when collisions between specific parts occur, but that’d be pretty difficult to do seeing as my map has like 5k of them. Thank you :slight_smile: Here’s the current code i’m using:

    if Switch.Value == false then
        Ki.Parent = Cac.Humanoid
        Ki.CFrame = Cac.HumanoidRootPart.CFrame
        Ki.Position = RHand.Position
        Switch.Value = true
        Cac.Humanoid:LoadAnimation(script.Parent.Parent.Animation):Play()
        local sound = script["Ki blast"]:Clone()
        sound.Parent = Ki   
        sound:Play()
        sound.Script.Disabled = false
        local Part = Ki 
        game.Debris:AddItem(Part, 6)
        local HRP = Player.Character:WaitForChild("HumanoidRootPart")
        local PPosition = RHand.Position + CFrame.new(RHand.Position,Mouse.p).lookVector * 1
        Part.CFrame = CFrame.new(PPosition, Mouse.p)
        Part:SetNetworkOwner(Player)
        local BV = Instance.new("BodyVelocity" , Part)
        BV.Velocity = HRP.CFrame.LookVector * 140
        BV.MaxForce = Vector3.new(1e8,1e8,1e8)
        wait(4)
        Part:destroy()
        return
    end
0
my english is bad but can you explain it with some more simple words, or i think you meant when they attack in mid air, it explodes Xapelize 2658 — 3y
0
my english is bad but can you explain it with some more simple words, or i think you meant when they attack in mid air, it explodes Xapelize 2658 — 3y
0
when I shoot, it goes through other parts, I want it to explode when it hits other parts PioIAm 6 — 3y

3 answers

Log in to vote
1
Answered by 3 years ago

i dk how to do that but i know how to make a killing block

0
good try Xapelize 2658 — 3y
0
oh ok ncihxad1123 12 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You can detect collision with BasePart:GetTouchingParts()

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

First you would need to make the script that detects when you touch it.

Script:

local part = script.Parent -- replace this with your part

part.Touched:Connect(function(hit)
    print('part is toutching ', hit.Name) -- will become explosion script later
end)

That script will print "part is touching [other thing]" in the console

Now we need to work on the explosion

We will need to get the Position of the part first so add this line after printing

local partPos = part.Position

(Btw name the variables anything you want it doesn't matter)

We will also need to create an explosion so add that line as well

local explosion = Instance.new('Explosion')

After that we parent it to your part and set its Position to the part's Position

explosion.Position = partPos
explosion.Parent = part

Finally after the explosion we delete your part

wait(1)
part:Destroy()

Heres the final script! (Note that if the part is touching something already it will trigger the explosion)

local part = script.Parent -- replace this with your part

part.Touched:Connect(function(hit)
    print('part is toutching ', hit.Name)
    local partPos = part.Position
    local explosion = Instance.new('Explosion')
    explosion.Position = partPos
    explosion.Parent = part
    wait(1)
    part:Destroy()
end)
1
Yeah! this is great, but is there any way to make it so that it doesn't damage yourself? It does exactly what I want, but I get blown to pieces whenever I shoot PioIAm 6 — 3y
0
You would have to set the "DestroyJointRadiusPercent" to 0. You would add this code after line 7 "explosion.DestroyJointRadiusPercent = 0" MarTieMak 56 — 3y

Answer this question