Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this damage players, and not blow them up?

Asked by 10 years ago

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)
0
I removed my answer due to random people - rep. Kozero 120 — 10y

2 answers

Log in to vote
2
Answered by 10 years ago

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)

Ad
Log in to vote
0
Answered by 10 years ago

use that when touched the bomb then the health will fall to 0 by this:

Game.Workspace.Player.Humanoid.MaxHealth = 0

Answer this question