Basically, if you touch the part, it will cause it to blowup, killing whoever touched it. But, I want it so it does 50 damage, instead of killing you instantly. Can anyone help?
function onTouched(part) script.Parent.Explosion:play() local boom = Instance.new("Explosion") boom.Parent = game.Workspace boom.Position = script.Parent.Parent.Bomb.Position parts = script.Parent.Parent:children() if parts.className == "Part" then parts:remove() end end script.Parent.Touched:connect(onTouched)
Here you go:
local d = true function onTouched(part) if d then d = false script.Parent.Explosion:Play() local boom = Instance.new("Explosion") boom.BlastPressure = 0 boom.Position = script.Parent.Parent.Bomb.Position boom.Hit:connect(function(hit) local human = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") if human and not human.Parent:FindFirstChild("Exploded") then human.Health = human.Health - 50 --This part is needed, so the player doesn't get damaged multiple times by same explosion local val = Instance.new("IntValue", human.Parent) val.Name = "Exploded" game:GetService("Debris"):AddItem(val, 0.1) end end) boom.Parent = game.Workspace parts = script.Parent.Parent:GetChildren()--Use getChildren, because children is depricated method. parts = script.Parent.Parent:GetChildren()--Use getChildren, because children is depricated method. for num, obj in pairs(parts) do if obj:IsA("BasePart") then obj:Destroy()--It's better to use Destroy instead of remove, because of same reasons end end --Also you had to use loop here, to delete contents of model(thought model will remain!) d = true end end script.Parent.Touched:connect(onTouched)
use that when touched the bomb then the health will fall to 0 by this:
Game.Workspace.Player.Humanoid.MaxHealth = 0