How do I make a touching function?

How do I make a function that triggers when a player is touching not touched. I am not that good on explaining but when a player is touching it. If the player leaves the part it will stop touching and if the player stands still it is still touching. Anyone know how I would script this?

You can use Touched and TouchEnded together to find out when a player steps on a part and steps off.

2 Likes

Another solution is using Region3, a similar problem is discussed here.

Yeah I tried using it and people in discord told me it was not good and stuff.

When you stand still TouchEnded will trigger so it will be hard.

WorldRoot:ArePartsTouchingOthers API Refrence could be used with the characters limbs and such.

1 Like

Like someone else said you can use Region3 or create your own function to check if someone is standing within certain bounds like this:

1 Like

What are you trying to make, also can you explain a bit more.

I am trying to learn scripting so I am making a simple capture the point game. It is 2 teams and if there is a other team on the point it will stop capturing and stuff.

That’s a bit confusing to understand lol. So basically if they capture the flag/point then the game ends?

Another solution if your mesh is cylindrical or spherical is to use magnitude

Nah I will code some more stuff to it.

Yeah people talked about that also. But I get a solution now.

I would read this abou Touched parts and stuff.

Using magnitude is the most elegant solution.

if (HumanoidRootPart.Position - CapturePoint.Position).Magnitude < 20 then
   -- Player is in the point
end

What about region? I need to add some nonsense so I can relpy.

image
I stood still and it only printed 8 times…

It only detected when I jumped for some reason.

Make sure the CapturePoint is at the center of the place where you want the player to be detected. And then the 20 to be the distance from the middle of the CapturePoint to the edge of where the player should be detected.

Region3 is more for checking if a point lies within space inside a cuboid, whereas Vector3.Magnitude will check whether something is within a sphere of something else, which is more useful for applications like this.