Basically, I need help with a part that's supposed to explode on contact if the part's parent isn't named "Enemy." I've checked the console and no errors are being given. If anyone could help, it'd be much appreciated! It also does a certain amount of damage depending how close you are to the part when it blows up (or when you shoot it, etc.)
The max damage is 75.
local maxDamage = 75
function onTouched(hitPart)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0
explosion.BlastRadius = 16
explosion.Hit:connect(function(hitPart, partDistance)
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
if humanoid and hitPart.Parent.Name ~= "Enemy" then
local distance_factor = partDistance/explosion.BlastRadius
distance_factor = 1 - distance_factor
if maxDamage*distance_factor >= 0 then
humanoid:TakeDamage(maxDamage*distance_factor)
end
end
end)
explosion.Parent = workspace
end
connection = script.Parent.Touched:connect(onTouched)

2 comments
You forgot a vital piece of information. You told us what you want to happen but you didn't tell us what is really happening.
Ah. Nothing is happening. At all. You touch the part and nothing happens.