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

Why doesn't this unanchor all parts it touches?

So this is a serverscript inside of a part I have moving forward. The part is anchored and cancollide true. It should make every part it touches cancollide false and unanchored.

local p = script.Parent
 
p.Touched:connect(function(obj)
    if obj.ClassName == "Part" and obj.Anchored == true then
        obj.Anchored = false
        obj.CanCollide = false
    end
end)


4 comments

0

Why are you searching for a Humanoid, and why are you trying to affect the part's CFrame?

0

Wait showed wrong code hold on

0

There's the actual code Im really sorry

0

The script worked perfectly fine when I tested it in a game with a Baseplate and another part... Check to make sure the Disabled property of the script is unchecked, and make sure the script's parent is in fact the part that you want the parts it touches to be not Anchored and not Cancollide.

3 answers

✓ Accepted answer

"So this is a serverscript inside of a part I have moving forward. "

You're most likely moving it forward with CFrame (correct me if i'm wrong). Well, as the wiki says, the Touched event won't fire if you're moving the part through something with CFrame. This is probably your problem.


You can use the method GetTouchingParts instead. This will return a table of all the parts that intersect with the part you called it on. It won't work for adjacent parts, only ones that intersect. It will also only work for parts that are CanCollide true.

Unfortunately, this isn't an event, so you'll have to use it in a loop. The best place would probably just be right after you move the part. Check out this simple script i just wrote:

local part = script.Parent

while wait() do
	part.CFrame = part.CFrame * CFrame.new(-0.1, 0, 0)
	for i, hit in ipairs( part:GetTouchingParts() ) do
		print(hit)
	end
end

1 comment

0

I'm sure this is it I can't test t out as I'm not able to access a computer but I think this is it thanks!

It could be that the parts you want to be unanchored/not CanCollide are not actually anchored, in which case anchoring them or removing the and obj.Anchored == true will fix the problem. Also, you may wish to use the IsA function instead of the ClassName property, like so:

local p = script.Parent

p.Touched:connect(function(obj)
    if obj:IsA("BasePart") then
        obj.Anchored = false
        obj.CanCollide = false
    end
end)

This will work with other types of parts, such as Wedges, Trusses and Unions.

i put it in a script inside a brick and it made all the parts that i had do that, even the baseplate, so i was just falling through over and over

2 comments

0

Please use the comment feature unless you're giving a legitimate answer.

0

Please keep your words to yourself when I couldnt post a comment on it in the first place.

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