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

Collision groups for characters not working?

As you can see in a previous post of myself, i had trouble making limbs invisible. i ultimately did it but now im trying to do the torso able to trespass objects, heres the script

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        Character.Archivable = true        
        while wait(0.1) do
            local clonedCharacter = Character:Clone()
            clonedCharacter.Parent = game.Workspace
            local delete = clonedCharacter:FindFirstChild("HumanoidRootPart")
            local Parts = clonedCharacter:GetChildren()
            for i,v in pairs(Parts) do 
                if v:IsA("Accessory") then 
                    v.Handle.Transparency = 0.5
                    v.Handle.CanCollide = false
                elseif v:IsA("BasePart") then 
	            local PhysicsService = game:GetService("PhysicsService")
	            local CharacterGroup = "CharacterGroup"
                local ClonedCharacterGroup = "ClonedCharacterGroup"

                PhysicsService:CreateCollisionGroup(CharacterGroup)
                PhysicsService:CreateCollisionGroup(ClonedCharacterGroup)

                local Ch1 = Character
                local Ch2 = clonedCharacter

                PhysicsService:SetPartCollisionGroup(Ch1, CharacterGroup)
                PhysicsService:SetPartCollisionGroup(Ch2, ClonedCharacterGroup)

                PhysicsService:CollisionGroupSetCollidable(CharacterGroup, ClonedCharacterGroup, false)
                    v.Transparency = 0.5
                    v.CanCollide = false
                    v.Anchored = true
                end
                delete:Destroy()
            end
        end
    end)
end)

Error: Parameter 2 must be BasePart in SetPartCollisionGroup / Line of error: 24

All help appreciated thanks.

1 answer

SetPartCollisionGroup can only work with a Part or BasePart. You are trying to set the character's model. Instead, use a loop to find all base parts inside the character model.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        Character.Archivable = true        
        while wait(0.1) do
            local clonedCharacter = Character:Clone()
            clonedCharacter.Parent = game.Workspace
            local delete = clonedCharacter:FindFirstChild("HumanoidRootPart")
            local Parts = clonedCharacter:GetChildren()
            for i,v in pairs(Parts) do 
                if v:IsA("Accessory") then 
                    v.Handle.Transparency = 0.5
                    v.Handle.CanCollide = false
                elseif v:IsA("BasePart") then 
                local PhysicsService = game:GetService("PhysicsService")
                local CharacterGroup = "CharacterGroup"
                local ClonedCharacterGroup = "ClonedCharacterGroup"

                PhysicsService:CreateCollisionGroup(CharacterGroup)
                PhysicsService:CreateCollisionGroup(ClonedCharacterGroup)

                local Ch1 = Character
                local Ch2 = clonedCharacter
		
		for _, v in pairs(Ch1:GetChildren()) do 
			if v:IsA("BasePart") then 
				 PhysicsService:SetPartCollisionGroup(v, CharacterGroup)
			end
		end
               
		for _, v in pairs(Ch2:GetChildren()) do 
			if v:IsA("BasePart") then 
				PhysicsService:SetPartCollisionGroup(v, ClonedCharacterGroup)
			end
		end

                PhysicsService:CollisionGroupSetCollidable(CharacterGroup, ClonedCharacterGroup, false)
                    v.Transparency = 0.5
                    v.CanCollide = false
                    v.Anchored = true
                end
                delete:Destroy()
            end
        end
    end)
end)

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