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

How to make a projectile do splash damage?

Asked by
steelflix -12
4 years ago
Edited 4 years ago

So I have a projectile that fires and whenever it hits an object I want it to do splash damage.

local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

local properties = {
   Size = Vector3.new(20, 20, 20),
   Transparency = 0.5
}

local properties2 = {
   Size = Vector3.new(0, 0, 0),
}

local Tween = TweenService:Create(script.Parent, TI, properties)
local Tween2 = TweenService:Create(script.Parent, TI, properties2)

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name ~= script.Creator.Value then
        script.Parent.Anchored = true 
        script.Parent.CanCollide = false
        Tween:Play()
        script.Parent.Blast:Play()
        Tween.Completed:Connect(function()
            Tween2:Play()
            Tween2.Completed:Connect(function()
                script.Parent:Destroy()
            end)
        end)
    end
end)

This script works fine and it allows the projectile to have a tween whenever it hits something where it starts increasing in size and covers an area, but for some reason whenever it increases in size, it does not deal damage to sorrounding players, why is this? The damage script fires inside the projectile with a Touched function (there is nothing wrong with the damage script as it works fine when you directly attack a player with the projectile instead of attempting to use splash damage).

1 answer

Log in to vote
0
Answered by 4 years ago

.Touched isn’t the best at collision, which is why you can jump on .touched bricks and not be damaged. There’s two other ways for hit detection, which are: Raycasting and distance. If your hit box is a sphere I suggest doing distance because it’s the most easiest and quick one.

However, in your example code you didn’t check for a humanoid and take health from that humanoid, so maybe you just forgot to take health off?

0
using explosions is a really cheap way, good on peformance though 123nabilben123 499 — 4y
Ad

Answer this question