#CollisionGroup

1 messages · Page 1 of 1 (latest)

sacred oak
#

I wanted to change player CollisionGroup to Player but problem is if I do it, its still 50/50 to work, sometimes it changes sometimes it doesnt,
is there a way to set the default of player without using scripts

local Players = game:GetService("Players")

local COLLISION_GROUP = "Player"

local function isInTool(instance)
    return instance:FindFirstAncestorOfClass("Tool") ~= nil
end

local function applyCollisionGroup(character)
    for _, part in ipairs(character:GetDescendants()) do
        if part:IsA("BasePart") and not isInTool(part) then
            part.CollisionGroup = COLLISION_GROUP
        end
    end

    character.DescendantAdded:Connect(function(desc)
        if desc:IsA("BasePart") and not isInTool(desc) then
            desc.CollisionGroup = COLLISION_GROUP
        end
    end)
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(applyCollisionGroup)
end)

for _, player in ipairs(Players:GetPlayers()) do
    if player.Character then
        applyCollisionGroup(player.Character)
    end
end