Player-collision script not working

Hey developers!

I’m trying to make a player-collision script, though it’s not working. I don’t know what I’m doing wrong. Any help would be appreciated! The code:

--Variables--
local playerSV = game:GetService("Players")
local physicsSV = game:GetService("PhysicsService")
local playercollisiongroup = physicsSV:CreateCollisionGroup("PlayerCollisionGroup")

--Script--
physicsSV:CollisionGroupSetCollidable("PlayerCollisionGroup", "PlayerCollisionGroup", false)

playerSV.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)	
		for _, child in ipairs(character:GetChildren()) do
			if child:IsA("BasePart") then
				physicsSV:SetPartCollisionGroup(child, "PlayerCollisionGroup")
			end
		end
	end)
end)

Have a nice day!

Well add this line and you will understand

player.CharacterAdded:Connect(function(character)
print(#character:children())

dont judge me for using deprecated stuff debugging

1 Like

It isn’t loaded yet… How would I make sure every basepart is loaded already??

2 Likes