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

how do i add on touched to this script it explodes without getting touched?

Asked by 3 years ago
while wait(1) do
    local EX = Instance.new("Explosion")
    EX.DestroyJointRadiusPercent = 0
    EX.Parent = script.Parent
    EX.Position = script.Parent.Position
    EX.BlastPressure = 1
    EX.BlastRadius = 5
    EX.Hit:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
            hit.Parent:FindFirstChild("Humanoid"):TakeDamage(2)
        end
    end)

end

it explodes without getting touched but i want it to explode on touch how do i do that

1 answer

Log in to vote
0
Answered by 3 years ago

Assuming the parent of the script is a part then a very simple way of doing it would be:

script.Parent.Touched:Connect(function(hit)
    if hit ~= game.Workspace then   -- the ~= means "Does not equal"
        local EX = Instance.new("Explosion")
        EX.DestroyJointRadiusPercent = 0
        EX.Position = script.Parent.Position
        EX.BlastPressure = 1
        EX.BlastRadius = 5

        EX.Parent = script.Parent
        --Setting the parent of an explosion to a part in the workspace will set th explosion to go off immediatly, and then delete itself after it is finished

    end
end)

I apologize if this script doesnt work but it should in theory.

Ad

Answer this question