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

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

Asked by 4 years ago

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:

01local part = script.Parent
02local debounce = false
03 
04part.Touched:Connect(function(hit)
05    if debounce == true then return end
06    debounce = true
07    local humanoid = hit.Parent.Humanoid
08    if humanoid.Health == 0 then return end
09    --Other Code stuff--
10end)

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

this should be it

01local part = script.Parent
02    local debounce = false
03 
04    part.Touched:Connect(function(hit)
05        if debounce == true then return end
06        debounce = true
07       if hit.Parent:FindFirstChild("Humanoid") then
08   --whatever you want to put
09        elseif hit.Parent:FindFirstChild("Humanoid").Health == 0 then return end
10    end)
0
please accept if this helped! peytonallen920 66 — 4y
1
Thanks! This helped a bit. ASimpleGalaxy 36 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

01local part = script.Parent
02local debounce = false
03 
04part.Touched:Connect(function(hit)
05    if not hit.Parent:FindFirstChild("Humanoid") then return end
06    if hit.Parent.Humanoid.Health == 0 then return end
07    if debounce == true then return end
08    debounce = true
09    --other code stuff--
10end)

Answer this question