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

How would I use Part.Touched so that it stops getting activated from accessories?

Okay so What is the best way to use this function??? Is there a better function to use??? Anyways, I have part and when the player hits it, it will activate some particle effects and stuff. The main problem I have is how when it hits a limb, you say hit.Parent to get the character... But it's not consistent cause it activates from a hat then you say hit.Parent and it just brakes everything. Is there a better way of doing this so that it's consistent and it will always get the character or humanoid or something.

Here is the first part of my code:

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	if debounce == true then return end
	debounce = true
	local humanoid = hit.Parent.Humanoid
	if humanoid.Health == 0 then return end
	--Other Code stuff--
end)

2 answers

✓ Accepted answer

this should be it

local part = script.Parent
	local debounce = false
	 
	part.Touched:Connect(function(hit)
	    if debounce == true then return end
	    debounce = true
	   if hit.Parent:FindFirstChild("Humanoid") then
   --whatever you want to put
	    elseif hit.Parent:FindFirstChild("Humanoid").Health == 0 then return end
	end)

2 comments

0

please accept if this helped!

1

Thanks! This helped a bit.

I thought i'd post this for other people cause it's better to do it this way.

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("Humanoid") then return end
	if hit.Parent.Humanoid.Health == 0 then return end
	if debounce == true then return end
	debounce = true
	--other code stuff--
end)

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