PhysicsService Error

Hello there! Recently I have had this problem where my PhysicsService is not working and it is driving me CRAZY!

game.Players.PlayerAdded:Connect(function(plr)
	local plrGroupRank = module.GetPlrRank(groupId,plr)
	local rank = plr:WaitForChild("leaderstats").Rank
	rank.Value = plrGroupRank
	
	plr.CharacterAdded:Connect(function()
		PhysicsService:SetPartCollisionGroup(workspace.BarBlockOff,"Doors")
		PhysicsService:SetPartCollisionGroup(workspace.BarBlockDoor,"Doors")
		PhysicsService:SetPartCollisionGroup(workspace.ReceptionBlockOff,"Doors")

		PhysicsService:CollisionGroupSetCollidable("Doors", "Plrs", false)
		
		for _,v in ipairs(plr.Character:GetChildren()) do
			if v:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(v,"Plrs")
				print(PhysicsService:CollisionGroupContainsPart("Plrs",v))
				print(PhysicsService:CollisionGroupsAreCollidable("Plrs","Doors"))
			end
		end
	end)
end)

My two checks print exactly what I want, but my character just does not go through the doors! Please help!

It could be that the CharacterAdded event is firing before the character’s body parts have all fully loaded. If so, then your character would not be able to go through the doors.

A way to fix this is to add a wait() function right before setting the character’s collision group. You can set it to a second or so, and increase it later if necessary. Let me know if this helps.

1 Like

It works! Thank you so much!! You have no idea how long I spent on this.

1 Like

Yeah, this has happened to me before, so I know the fix for it.

1 Like

Just a quick question: How did you find how to fix it?

I know how the server loading system works and how it replicates, so I know that there’s a delay for character body part loading.

BTW there is a better solution, you could use:

character.DescendantAdded()
1 Like