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

Help with this punch tool?

function onDamage(Part)
	if Part.Parent:FindFirstChild("Humanoid")~= nil and Part.Parent.Name ~= "script.Parent.Name" then 
		
			Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -3.4
		end
	end

script.Parent.Parent.Parent.Character["Left Arm"].Touched:connect(onDamage)
--It works but I want it to only damage when I press q the problem is when I touch a humanoid My left arm damages them when I dont want them to.Help?

2 comments

0

This is a less important thing, but take script.Parent.Name out of quotes. It's checking to see if the parent (of the part)'s name is equal to, literally, "script.Parent.Name", and I'm sure your character isn't named script.Parent.Name.

0

Answer?

1 answer

You are checking to see if the parent of the part's name is equal to the string, "script.Parent.Name".

e.g: is the parts name equal to Script.Parent.Name

So try this instead:

script.Parent.Parent.Parent.Character["Left Arm"].Touched:connect(function()
    if Part.Parent:FindFirstChild("Humanoid")~= nil and Part.Parent.Name ~= script.Parent.Name then 
            Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -3.4
        end
end)

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