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)
"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
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