Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if child.CanCollide then is not working as I thought?

Asked by 6 years ago
for index, child in pairs(wendigoParts) do
    print(child.Name)
    if child.CanCollide then
        print(child.Name, " Can Collide")
        PhysicsService:SetPartCollisionGroup(child, wendigoGroup)
    end
end

The script is always stopping on the

if child.CanCollide then

It is stopping when it runs into something that does not have the CanCollide inside of it. I thought the if CanCollide ment if it has the CanCollide feature the next line runs?

0
Try using if child:IsA("BasePart") and child.CanCollide then Async_io 908 — 6y
0
if child.CanCollide actually checks if it is true, not if it is a property. PoePoeCannon 519 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try this code:

for index, child in pairs(wendigoParts) do
    print(child.Name)
    if child:IsA("BasePart") and child.CanCollide then
        print(child.Name, " Can Collide")
        PhysicsService:SetPartCollisionGroup(child, wendigoGroup)
    end
end

Changes that I made: (Thanks to @NathanTheDeveloper): Tested to see if child was a BasePart and if it had true for CanCollide

Ad

Answer this question