Roblox tool Not damaging Holder

I’ve been recently been making a game and the tool that you use to fight other players have a kill brick attached to the end of it. this kill brick is causing issues as the tool will fall to your feet as you walk and damage you.
i’m looking for a saluting that will still allow the kill brick to damage other players but not damage the person that is holding it. if it helps there is no way to drop the tool.
im not very good at scripting but i tried to do something
if game.Players.PlayerAdded:Connect(function(plr)
if plr.name == not script.Parent.Parent.Parent then
the reason i tried script.parent.parent.parent is because its a part, in a tool, in the players toolbox, in the player

2 Likes

If you use a touched event then you could just filter it out by not damaging if it touches their arm or something

1 Like

I need something that will work over the entire body of the person who is holding the tool

Check the parent of the part that got hit and see if it has the same name as the player, or tools parent.

1 Like

that gives me an idea would it be possible to set the parts parent to the player that is holding it?

1 Like

Check out Roblox’s “Sword Tool Example” on the wiki page here.

2 Likes

A few issues with this, You can not do an if statement on a Connection like this. You are checking if a string is equal to an object. plr.Name would give you a string. But script.Parent.Parent.Parent.Parent gives you the player. Let’s say the player’s name is Player1 then you are essentially doing.
if "Player1" == game.Players.Player1 then
which will always give you false. Also, the PlayerAdded event is ran before any tool is added to the player before StarterGear is inserted into it. However, seeing as the script appears to be inside the tool this code shouldn’t run at all because the code would be ran after the player has joined. ( Your code is confusing so this might be wrong ) On the kill brick, I recommend doing something like this.

local tool = script.Parent
local Killbrick = tool.KillBrick

Killbrick.Touched:Connect(function(Part)
	local Body = Part.Parent
	local Humanoid = Body:FindFirstChild("Humanoid")
	if Humanoid then
		if Body ~= tool.Parent then
			Humanoid:TakeDamage(10)
		end
	end
end)

However, doing this does have some downsides. First of all. An exploiter is able to change the size of the part to damage a person who is far away. Or just straight-up teleport the killing part on to the player. I recommend checking the distance between the part and the person being damaged using magnitude. Also, check out that wiki link that was handed out to you!

2 Likes

thanks for that i’ll need to try and edit it to work with what im doing with it but its a great start and i still need to become better at scripting thanks for showing me why what i was doing was not working.

1 Like

after editing the local killbrick to local Killbrick = script.parent it worked thank you so much :smiley: