Help me in Touched Event pls

I’ve been a programmer for a long time, but I never had any problems using the Touched () function, but in my current game (My Game), I had an error, I basically have a skill script, which clones and positions a “Rock” in the workspace and whoever touches it will take damage, it works perfectly on players, but my NPCS (dummys) are not working, and I already found the error, to be able to trigger the Touched () at least one part it can’t be anchored, that’s my problem, because my dummy is not for getting around, so I activate the anchor on his “leg” and the rest will be without anchor to be able to play animation, but it seems that for some reason the "NPC “changes the” Anchored “property, because when running the Script the ´Touched () ´ function will not be connected until all the children of an NPC are without anchor, I could disable anchoring in my” Rock "(part of the skill) but that wouldn’t give you the skill, if someone could help me with this problem I would be very grateful. (Maybe this may seem confusing)

This is my NPC:


as you can see, he has a leg, which will be his “base”, this base that would have to be anchored.

Unfortunately, I believe if any of the parts are anchored, the entire assembly (all of the parts attached to the anchored part through motors or constraints) will not trigger touched events.


any idea how to get around this?

What if you script the NPC to get to that Position so it stays there, even if pushed?

why not use magnitude? more reliable too; following up on @Scottifly’s post here is an example:

local part = yourpart
local cframe = part.CFrame

while part.CFrame ~= cframe do
   part.CFrame = cframe
1 Like

won’t that give a lot of lag?

you can use a more efficient loop such as a for i,v but that was just an example; and no magnitude does not give lag

I added this script to my NPC but it didn’t “anchor” it

and what would be a “Magnitude”

1 Like

that was pseudo-code, not something for you to copy and paste.

here read about magnitude:

also you really aren’t living up to this:

1 Like

would that be more effective in “SetAttributeChangeSignal ()”?

Maybe make an invisible part that would act like a hitbox for the NPC and listen for the touched event instead of the NPC itself?

I would try that but the “HitBox” wouldn’t have to be anchored either?

touched is unreliable, you should know that if you have been scripting for a “long time” ; use magnitude to detect how close they are or use region3; although i would use magnitude.

maybe the translator is wrong, I meant that I work with scripting for a short time but not too short (I’m from Brazil)

Could you give me an example of how to use magnetude or region3 on this occasion?

local magnitude = (yourpart - Character.HumanoidRootPart).Magnitude
if magnitude <5 then

of course with this you will need to modify some things; but it’s some pseudo code that will help you understand magnitude.

it is not so difficult to work with it but I will have to create a loop to check, and my skill will make several stones (50 ~ 100) to cause damage creating a loop on all stones will not cause delay? (sorry if I’m being boring)

i don’t know; you may want to make a different post on that as it is out of the scope of your question but here:

  1. touched events with 100 part’s will create IMMENSE lag. you may want to make a damage module
  2. why not create a large hitbox and drain the humanoids health every X seconds? it would make it look like they are getting hit by tons of stones

I think it would not be a good one, even using magnitude, I would have to check the distance of the stone and a “Torso” of many Npc that I have in my game (30 ~ 50)