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

How can I make a damage script not damage the player holding the tool?

Asked by 3 years ago
Edited 3 years ago

i tried

if char:findFirstChild("Tool") then

I didnt know what to do next make the health infinite? that wouldnt work its a fighting game. I dont know if this is possible but yeah. I know the handle doesnt damage the player, but im not using a handle

2 answers

Log in to vote
0
Answered by
Despayr 505 Moderation Voter
3 years ago
Edited 3 years ago

You will need to add another check. Example

remote.OnServerEvent:Connect(function(plr)
    local character = plr.Character
    local newPart = Instance.new("Part")
    newPart.Anchored = true
    newPart.Position = Vector3.new(0,0,0)

    newPart.Touched:Connect(function(hit)
        if hit:IsDescendantOf(character) then return end --the check
        print("KONO DIO DA")
    end)

end)

The touched event sends the part that was touched as a parameter. Using :IsDescendantOf() is a check to see if the part that was touched is a part of the players character

0
i didnt really get that but yeah proudCdthekitten 22 — 3y
1
To reiterate. The .Touched signal fires when contact is made with the affiliated BasePart, I.e a Collision-Detection. The signal will call upon the bound callback, and pass the part-of-contact along with it. Ziffixture 6913 — 3y
1
That part-of-contact, in PvP, is normally a body part in a Character rig. With that we can locate a Humanoid and call :TakeDamage(). Ziffixture 6913 — 3y
1
The Hitbox integrated into the Tool has a chance of detecting the wielder, though, in our code we don't accommodate for that, therefore we still proceed with dealing damage to a Humanoid. Ziffixture 6913 — 3y
1
In the program above, Despayr adds a debounce line that checks whether the part-of-contact is a descendant of your avatar's rig. If so, the function is then halted with the return call, and effectively canceled. Ziffixture 6913 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local Debounce = false

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
        Debounce = true
        hit.Parent.Humanoid:TakeDamage(100)
        wait(1)
        Debounce = false
    end
end)

This script will make damage to a player.

0
That's not what he's looking for. Ziffixture 6913 — 3y

Answer this question