Hello!
So i’ve ran into a issue related to the GetTouchingParts()
function when i was coding a custom vehicle explosion effect with it.
The explosion is supposed to damage any Humanoid
that is within the ExplosionPart
with a tenth of the vehicle’s MaxHealth
. it works but, since characters have multiple parts, and it detects them, it causes them to end up taking way too much damage than they actually should, and i can’t think of a way to prevent that from happening.
This the section of the script that manages the explosion and damage to humanoids:
local Parts = ExplosionPart:GetTouchingParts()
local Affected = {}
for i, v in next, Parts do
local Distance = (v.Position - ExplosionPart.Position).Magnitude
local DistanceFactor = Distance / ExplosionPart.Size.Magnitude
local Humanoid = v.Parent:FindFirstChildWhichIsA("Humanoid")
DistanceFactor = 1 - DistanceFactor
table.insert(Affected, v)
if Humanoid and Humanoid.Parent:IsA("Model") then
local RootPart = Humanoid.Parent:FindFirstChild("HumanoidRootPart")
Humanoid:TakeDamage((Stats.Health.MaxHealth.Value / 10) * DistanceFactor)
Humanoid.PlatformStand = true
delay(.05, function()
if RootPart and RootPart:IsA("BasePart") then
local DirectionVector = (RootPart.CFrame.p - ExplosionPart.Position).Unit
local Velocity = (DirectionVector * (tonumber(Stats.Main.ExplosionForce.Value)) * DistanceFactor)
RootPart.Velocity = RootPart.Velocity + Velocity
end
end)
delay(math.random(25, 30) / 10, function()
Humanoid.PlatformStand = false
end)
end
delay(2, function()
table.remove(Affected, 1)
end)
end
Also, it seems that i cannot apply any velocity to the characters RootPart
for some reason, as they are supposed to be pushed away from the explosion. Am i doing something wrong?