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

Why isn't this making the player take damage when being shooting at a block?

Asked by 9 years ago

This script is supposed to make the person that shot it take 8 damage, unfortunately that only happens if you step on it! Why doesn't it work if you shoot it?

Part12 = script.Parent
function Hit(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if human ~= nil then
        human.Health =  human.Health -8
    end
end

Part12.Touched:connect(Hit)

Please help!!! Thank you!

-This is not my script-

0
I don't see anything wrong with this... you might have a Hierarchy problem. There's no Output? alphawolvess 1784 — 9y
0
not for anything relevant to this script yogipanda123 120 — 9y

1 answer

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
9 years ago

The Touched event triggers when the geometrical representation of an instance that inherits from BasePart intersects that of another. When A intersects with B, A and B both fire a Touched event.

The script that you posted will only work in these circumstances:

  • The weapon fires physical (BasePart inheriting) projectiles

  • The projectiles that are fired are parented to the character Model of the Player

If you parent the projectiles to the character Model of the Player, this script will work. If your weapon does not use physical projectiles, but rather another method (such as ray casting) then your script will not work because the Touched event does not fire when detected by a ray.

Ad

Answer this question