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

How do I make my projectile only explode when it hits a player?

Asked by 7 years ago

I would like to know how to make my projectile explode when it touches PLAYERS. Whenever I use it, it explodes when touching ANYTHING. Please help :D <3 btw I have another script adding the velocity and such just so you all know :D

local part = game.Workspace.BallEx
part.Transparency = 0.3

local fire = Instance.new("Fire")
        fire.Color = Color3.new(108, 91, 236)
        fire.SecondaryColor = Color3.new(104, 0, 139)
        fire.Heat = 25
        fire.Size = 30
        fire.Parent = part

part.Touched:Connect(function()

    local explosion = Instance.new("Explosion")
        explosion.BlastPressure = 50000
        explosion.BlastRadius = 10
        explosion.Parent = game.Workspace
        explosion.Position = part.Position
    part:Destroy()
end)

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
7 years ago
Edited 7 years ago
local part = game.Workspace.BallEx
part.Transparency = 0.3

local fire = Instance.new("Fire")
        fire.Color = Color3.new(108, 91, 236)
        fire.SecondaryColor = Color3.new(104, 0, 139)
        fire.Heat = 25
        fire.Size = 30
        fire.Parent = part

part.Touched:Connect(function(Touched)
    if Touched.Parent:FindFirstChild("Humanoid") then
        local explosion = Instance.new("Explosion")
            explosion.BlastPressure = 50000
            explosion.BlastRadius = 10
            explosion.Parent = game.Workspace
            explosion.Position = part.Position
        part:Destroy()
    end
end)

This checks to see if there is a humanoid inside of the parent of the object it hits, which all players have.

0
TYSM! :D iizWishzii 21 — 7y
Ad

Answer this question