Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

5 comments

0

i didnt really get that but yeah

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.

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().

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.

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.

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.

1 comment

0

That's not what he's looking for.

This discussion is preserved as it was. New answers, comments, and votes are closed.