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

Damage script works only once?

Asked by
lucas4114 607 Moderation Voter
8 years ago

I have the part here: https://gyazo.com/afd73a7fec4f7d097e99a3dcb95d2076 And it does work, but the problem is only once, when the ai walked into the other one it damaged him but only that time then it just did nothing. Example: https://gyazo.com/6789f6f4c1fc9d7a6552cd3add2f3338 (It did damage it, it just healed before I could get it in the gif) How do I fix it??

script.Parent.Touched:connect(function(part)
    local humanoid1 = part.Parent:FindFirstChild("Humanoid")
    local humanoid2 = part.Parent.Parent:FindFirstChild("Humanoid")
    if humanoid1 then
        humanoid1:TakeDamage(script.Parent.Damage.Value)
    end
    if humanoid2 then
        humanoid2:TakeDamage(script.Parent.Damage.Value)
    end
end)
0
It should work :/ TheDeadlyPanther 2460 — 8y
0
^ ObscureEntity 294 — 8y
0
It works.......... Only on first touch. :/ lucas4114 607 — 8y
0
I tested the script, and everything went well. rexbit 707 — 8y

2 answers

Log in to vote
0
Answered by
joalars2 107
8 years ago

Try this;

script.Parent.Touched:connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then

        hit.Parent.Humanoid:TakeDamage(script.Parent.Damage.Value)

    elseif hit.Parent.Parent:FindFirstChild("Humanoid") then

        hit.Parent.Parent.Humanoid:TakeDamage(script.Parent.Damage.Value)

    end

end)

Might work.

Ad
Log in to vote
0
Answered by 8 years ago

Put a part in ReplicatedStorage and put this script in it :

script.Parent.Touched:connect(function(part)
    local humanoid1 = part.Parent:FindFirstChild("Humanoid")
    local humanoid2 = part.Parent.Parent:FindFirstChild("Humanoid")
    if humanoid1 then
        humanoid1:TakeDamage(script.Parent.Damage.Value)
    end
    if humanoid2 then
        humanoid2:TakeDamage(script.Parent.Damage.Value)
    end
game.ReplicatedStorage.PARTNAME:Clone().Parent = game.workspace
end)

And put another part with this script in workspace.

I hope it helped !

Answer this question