CollisionGroup is deprecated

Hello there!
Im trying to make a player only door and after some basic search i got something out a tutorial but then i figured it was kinda outdated and some errors cameup.
Im pretty new at scripting so cant really brain it by myself.

SetPartCollisionGroup is deprecated, please use BasePart.CollisionGroup instead. More info: Updates to Collision Groups

how can i fix this error?

-- Roblox services
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")


local npcModel = script.Parent

-- the name of the group rather than referencing the group itself, so saving these
local playerGroup = "Players"
local npcGroup = "NPCs"

-- Create the collision groups and set them to not collide with each other
local function collisionGroupExists(groupName)
	local groups = PhysicsService:GetRegisteredCollisionGroups()
	for _, group in ipairs(groups) do
		if group.name == groupName then
			return true
		end
	end
	return false
end
if not collisionGroupExists(npcGroup) then
	PhysicsService:CreateCollisionGroup(npcGroup)
end
if not collisionGroupExists(playerGroup) then
	PhysicsService:CreateCollisionGroup(playerGroup)
end
PhysicsService:CollisionGroupSetCollidable(npcGroup, playerGroup, false)

-- Helper function to recursively set the collision group on an object and all of
-- its children
local function setCollisionGroupRecursive(object, group)
	if object:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(object, group)
	end
	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child, object)
	end
end

-- Function called when a player character joins the game
local function onCharacterAdded(character)
	-- Put all of the current parts of the model into the player collision group
	setCollisionGroupRecursive(character, playerGroup)
	
	-- Put any part that gets added to the character later into the collision group
	character.DescendantAdded:Connect(function(descendant)
		if descendant:IsA("BasePart") then
			PhysicsService:SetPartCollisionGroup(descendant, playerGroup)
		end
	end)
end

-- Function called when a player joins the game
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

-- Sets the collision group of Blue to the npc group
setCollisionGroupRecursive(npcModel, npcGroup)

-- Bind PlayerAdded event to onPlayerAdded
Players.PlayerAdded:Connect(onPlayerAdded)

-- Make sure to add any characters that are currently in the game
-- to the collision group (otherwise the above event wouldn't catch
-- them
for _, player in ipairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

This isn’t necessarily an error; rather, it’s a deprecation warning. I recommend reviewing the article associated with the warning and exploring the Collision Filtering guide available in the Creator Hub for more information.

All its Telling you to do is to replace :SetPartCollisionGroup() with BasePart.CollisionGroup, this basically means that you have to change the property of the BasePart (The Object you are trying to Change CollisionGroups with) instead of using the function.

A BasePart is a Class that all Parts WedgeParts MeshParts Inherit from, All Properties and Data should be applied to them, which includes the CollisionGroup Property, which is the Property that has superseded :SetPartCollisionGroup().

1 Like