Local touching local issues

So I have an object, call it “part A”, and a group of objects, call it “rig A”. So Part A needs to run a code once it comes in contact with any part within rig A. The issue is my game uses local scripts to clone part A and rig A. So the traditional Touch codes don’t work. Along with that the parts are all anchored as to keep them from falling out of the world.
How would I get two parts both anchored and local created to run a code when they collide or overlap?

1 Like

The only way is to use a server script instead.

1 Like

But the objects themselves are local clones.

Then you should clone them on the server

1 Like

Then people who arent supposed to see them, will see them.

You can actually use a local script for a touched event for something that for created in the local script. I used it and it worked perfectly in my simulator where the player has to touch crystals and the crystals disappear on touch. Just don’t use the touched event in a local script under a server created part.

From the roblox api wiki:

“…[.Touched] will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be BasePart.Anchored at the time of the collision”

Even if you tried the touched script on the server, it will not work. The best solution is to use a different detection system to find when parts overlap. You can do this in multiple ways:

  1. Use :GetTouchingParts() on a loop.

  2. Use Region3 to find parts within a box.

  3. Use RayCasts on a loop to find any parts it hits.

The part is created via a local script that cloned it and the script along with it is also cloned and local. Also, a normal :Touched() fuction does not work because they are anchored.

I have tried :GetTouchingParts as well as Region3 but it still returns nothing.
If you’d like to have a discord call in the morning, its 12 AM for me, It would be easier to do there.

Region3 would return something. Make sure to call it from the localplayer. I also recall that it had a limit for how many parts it returns but I can’t find it.

:GetTouchingParts() is special because it will only return something if the basepart it was called on has CanCollide = true. You can attach a .Touched event to the basepart then call :GetTouchingParts() to avoid this.

Just use touched event on a part created locally.

Found it: workspace:FindPartsInRegion3(Region3, Ignore, MaxCount)

So you can call workspace:FindPartsInRegion3(Region3, nil, math.huge) to find insersecting parts in a box.

Would this work for parts that are cylindrical and spherical or would it automatically get them all to be square?

:FindPartsInRegion3() is restricted to a box and it cannot be rotated (but there are rotated modules out there in the devforums).

I recommend using :GetTouchingParts() because it uses the collision geometry of the BasePart to detect collision, so you can detect anything in a sphere, cylinder, sword, ship, etc.

The issue is I’ve tried :GetTouchingParts() but it still doesnt print anything. They are anchored but that shouldn’t matter. The issue I feel it is is that they are both cloned objects therefor making them not see each other.
Local script is cloning them. Two different local scripts, but they are from the same player.

:GetTouchingParts() is special because it will only return something if the basepart it was called on has CanCollide = true. You can attach a .Touched event to the basepart then call :GetTouchingParts() to avoid this.

Having parts cloned from 2 different localscripts from the same client will not prevent them from being collision detected. The only time parts cannot be detected is when one player clones a part for their client and another player clones a part for their client. Because the parts are cloned onto different clients, it is not possible to detect the collision of those cloned parts on the opposite client.

I would think so but if I clone neither they detect each other, clone both they don’t. So its a really odd
issue.

Ok so I figured it out. The code does not work if its cloned so I set it up in such a way that it doesn’t need to be. Thank you everyone for the help.