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

How to damage everyone who touches a part?

Asked by 8 years ago

I'm asking if I can damage everyone who touches that part in the same time, and damage not being glitchy, also without script.disabled and script.enabled since that's not very good for me...

1 answer

Log in to vote
4
Answered by
rexbit 707 Moderation Voter
8 years ago

Start off by using the Touched event.


script.Parent.Touched:connect(function(Hit)
    return Hit
end)

This is a basic Touched event that fires when touched, The Hit parameter is a object that Interacts with the Part. Next, damage the player, but we'll check if Hit is a Player, by accessing the player and search for a Humanoid.


script.Parent.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        return Hit
    end
end)

Now the final step, taking damage, You can take damage by using the TakeDamage method.


Damage_Taken = 50

script.Parent.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        Hit.Parent.Humanoid:TakeDamage(50)
    end
end)

Ad

Answer this question