plrs = game:GetService("Players")
ps = game:GetService("PhysicsService")
ps:RegisterCollisionGroup("plrs")
ps:CollisionGroupSetCollidable("plrs","plrs",false)
plrs.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
for key,value in pairs(chr:GetDescendants()) do
if value:IsA("BasePart") then
value.CollisionGroup = "plrs"
end
end
end)
end)
this is suppose to disable player collisiosn but it doesnt what is wrong with this code
When CharacterAdded signal is received, a bit portion of the character is probably not loaded in workspace yet.
For individual instances, we can use WaitForChild, e.g. character:WaitForChild("Head").
Here is a solution a version of which you would find in my projects.
function CollisionService:AddModelToGroup(model: Model, group: string, listen_for_new_descendants: boolean): ()
if not PhysicsService:IsCollisionGroupRegistered(group) then
warn(
string.format("Given collision group is not registered. Group: %s"), tostring(group)
)
end
for _,v in model:GetDescendants() do
if v:IsA("BasePart") then
v.CollisionGroup = group
end
end
if listen_for_new_descendants then
model.DescendantAdded:Connect(function(descendant)
if descendant:IsA("BasePart") then
descendant.CollisionGroup = group
end
end)
end
end
The connection should get disconnected once the model is destroyed, as of two days ago, even on characters on the server (New Player and Character Destroy Behavior), if you enable workspace.PlayerCharacterDestroyBehavior.
Also, make sure `Players.PlayerAdded` is actually connected before the first player joins. Otherwise, at least loop through players that are there already.
local function OnCharacterAdded(character: Model): ()
-- ...
end
local function OnPlayerAdded(player: Player): ()
player.CharacterAdded:Connect(OnCharacterAdded)
end
for _,player in Players:GetPlayers() do
OnPlayerAdded(player)
end
Players.PlayerAdded:Connect(OnPlayerAdded)