So i have an example where the blast explosion both touch the Head and the Torso. I want to add both damage that was hit by the blast where Head = 75 and torso = 20. The Problem is it only prioritize the first condition and ignore the rest. How can I add or get the total damage if blast touch both head and Torso?
local BlastPart = script.Parent
BlastPart.Touched:Connect(function(hit)
if hit.Name == "Head" then
hit.Parent:FindFirstChild("Humanoid").Health:TakeDamage(70)
elseif hit.Name == "Torso" then
hit.Parent:FindFirstChild("Humanoid").Health:TakeDamage(20)
end
end)
Not exactly sure what the problem is. This script can hit the torso or head multiple times. You might want to use like get bounds in box or get parts in region3… Not sure what you mean is happening wrong tho…
Are you sure the character has a “torso” and not an upper and lower torso? Other than that idk why it wouldn’t do both unless you’re not touching the torso.
You can create a variable called touched and assign its initial value to false and then once it has hit someone, set it to true. Also, you should make sure a humanoid object exists before trying to modify it because, if one isn’t found, FindFirstChild returns nil.
local BlastPart = script.Parent
local touched = false
BlastPart.Touched:Connect(function(hit)
local humanoid = hit.Parent and hit.Parent:FindFirstChild('Humanoid')
if not touched and humanoid then
if hit.Name == "Head" then
humanoid.Health:TakeDamage(70)
touched = true
elseif hit.Name == "Torso" then
humanoid.Health:TakeDamage(20)
touched = true
end
end
end)
local BlastPart = script.Parent
local damages = {["Head"] = 75, ["Torso"] = 25}
local parts = workspace:GetPartsInPart(BlastPart)
for _, hit in ipairs(parts) do
local hitName = hit.Name
local damage = damages[hitName]
if damage then
local humanoid = hit:FindFirstAncestorOfClass("Model")
if humanoid then
humanoid:TakeDamage(damage)
end
end
end