Collision Group Not Working

Hello, the Collision Group that I made isn’t working. I want the player to not be able to collide with any part named “Glass” in the workspace. (Right now they can collide with it) Here is the code:

local function collisions(player)
	local char = player.Character or player.CharacterAdded:Wait()
	task.spawn(function()
		for i, v in pairs(game.Workspace:GetDescendants()) do
			if v.Name == "Glass" then 
				v.CollisionGroup = "Glass"
			end
		end
	end)
	
	task.spawn(function()
		for i, v in pairs(char:GetDescendants()) do
			if v:IsA("Part") or v:IsA("MeshPart") then
				v.CollisionGroup  = "Player"
			end
		end
	end)
end

And here is the Collision Group Editor:
image

If you put a print in the funtion. Does it print anything?

task.spawn(function()
	for i, v in pairs(game.Workspace:GetDescendants()) do
		if v.Name == "Glass" then 
			v.CollisionGroup = "Glass"
		end
	end
end)

Put this outside the function

Yes, it does, and I will try doing the extra task right now

I still have collisions with the part.

print the name of v

task.spawn(function()
	for i, v in pairs(char:GetDescendants()) do
		if v:IsA("Part") or v:IsA("MeshPart") then
            print(v.Name)
			v.CollisionGroup  = "Player"
        end
	end
end)

try this function:

local function setCollisionGroup(instances,collisionGroup)
	for _, part in instances do
		if part:IsA("BasePart") then
			part.CollisionGroup = collisionGroup
		end
	end
end

setCollisionGroup(char:GetDescendants(),"Player")

Same issue. sdlkfjsdfkljsdfklfsd

are you sure you need to use collision groups and can’t use glass.CanCollide = false

Yes, 100 percent sure sdfsdf sdf sdf sdf sdf sdf

check in their properties collision group and tell me if they are correct. both glass and player

yes, they are both correct
sdf sdfsdf

Try using v:IsA(“BasePart”) instead:

local function collisions(player)
	local char = player.Character or player.CharacterAdded:Wait()
	
	task.spawn(function()
		for i, descendant in ipairs(workspace:GetDescendants()) do
			if descendant.Name == "Glass" then 
				descendant.CollisionGroup = "Glass"
			end
		end
	end)

	task.spawn(function()
		for i, descendant in ipairs(char:GetDescendants()) do
			if descendant:IsA("BasePart") then
				descendant.CollisionGroup  = "Player"
			end
		end
	end)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.