Player Collision Script Not Working

I’m trying to make it so that the player can only collide with some things but even with this code I still collide with the things that I don’t want to but I get no errors.

local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")

Players.PlayerAdded:Connect(function(player)
	print("hi")
	player.CharacterAdded:Connect(function(character)
		print("bye")
		for i, object in ipairs(character:GetDescendants()) do
			if object:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(object, "Player")
			end
		end
	end)
end)

I even have checks Hi and Bye and they both go through.

Screenshot 2022-01-12 100339

These are my collision groups.

1 Like

have you tried Disabling
image
this checkmark and enabling the other 2

I tried but then is collides with nothing and falls out of the map

Did you check if the body parts or part is CanCollide?

That wouldn’t work because that would just make him able to collide with other players and the mobs.

Also did u do script for the mob where you set the collision group?