Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A Problem with Player-Player Collisions?

Asked by 3 years ago

I'm trying to code a Player-Player Collisions system. But Player and Player are still be able to collide each other Note: Im in Local Server Testing Mode

game.Players.PlayerAdded:Connect(function(plr)
    local PhysicsService = game:GetService("PhysicsService")
    local Character = plr.Character
    local PlayerCollisionGroup = PhysicsService:CreateCollisionGroup("Players")
    PhysicsService:CollisionGroupSetCollidable(PlayerCollisionGroup, PlayerCollisionGroup, false)
    for index, value in pairs(Character:GetDescendants()) do
        if value:IsA("BasePart") then
            value.CollisionGroupId = PhysicsService:GetCollisionGroupId("Players")
        end
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
game:GetService("Players").PlayerAdded:Connect(function(plr)
    local PhysicsService = game:GetService("PhysicsService")
    local Character = plr.Character
    local PlayerCollisionGroup
    local success,fail = pcall(function()
        PlayerCollisionGroup = PhysicsService:GetCollisionGroupId("Players")
    end)
    if fail then
        PlayerCollisionGroup = PhysicsService:CreateCollisionGroup("Players")
        PhysicsService:CollisionGroupSetCollidable("Players","Players",false)
    end
    for index, value in pairs(Character:GetDescendants()) do
        if value:IsA("BasePart") then
            PhysicsService:SetPartCollisionGroup(value,"Players")
        end
    end
    plr.CharacterAdded:Connect(function()
        wait(1/30)
        Character = plr.Character
        for index, value in pairs(Character:GetDescendants()) do
            if value:IsA("BasePart") then
                PhysicsService:SetPartCollisionGroup(value,"Players")
            end
        end
    end)
end)
Ad

Answer this question