I’m making a zombie game and theres different types of zombies and I added an Explosive one but I only want it to damage players and not other zombies.
I have tried to do it but to no effect, it just ended up not damaging anything.
Code:
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0
explosion.DestroyJointRadiusPercent = 0
explosion.BlastRadius = radius
explosion.Position = position
local modelsHit = {}
-- listen for contact
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
if modelsHit[parentModel] then
return
end
modelsHit[parentModel] = true
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
if humanoid:FindFirstChild("Zombie") then
if humanoid:FindFirstChild("Zombie").Value ~= true then
local distanceFactor = distance / explosion.BlastRadius
distanceFactor = 1 - distanceFactor
humanoid:TakeDamage(maxDamage * distanceFactor)
else
return nil
end
end
end
end
end)
explosion.Parent = game.Workspace
end