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

Sorry for the repost, but how do you make a part collide with everything but players?

Asked by 5 years ago
Edited 5 years ago

I tried reading the wiki for collision filtering, but I still couldn't figure it out. I actually have a script already I got from the wiki that allows no player collisions, so is there an easy way to change it so players also don't collide with parts named "Handle" along with players (which is already in the script)?

local PhysicsService = game:GetService('PhysicsService')

PhysicsService:CreateCollisionGroup('Players')
PhysicsService:CollisionGroupSetCollidable('Players', 'Players', false)

local function disableCollision(obj)
    if obj:IsA('BasePart') then
        PhysicsService:SetPartCollisionGroup(obj, 'Players')
    end
end

local function setup(model)
    for i, obj in pairs(model:GetDescendants()) do
        disableCollision(obj)
    end
    model.DescendantAdded:connect(function(obj)
        disableCollision(obj)
    end)
end

game:GetService('Players').PlayerAdded:connect(function(player)
    if player.Character then
        setup(player.Character)
    end
    player.CharacterAdded:connect(function(char)
        setup(char)
    end)
end)

1 answer

Log in to vote
0
Answered by
ben0h555 417 Moderation Voter
5 years ago
local PhysicsService = game:GetService('PhysicsService')

PhysicsService:CreateCollisionGroup('Players')
PhysicsService:CollisionGroupSetCollidable('Players', 'Players', false)

local function disableCollision(obj)
    if obj:IsA('BasePart') then
        PhysicsService:SetPartCollisionGroup(obj, 'Players')
    end
end

local function setup(model)
    for i, obj in pairs(model:GetDescendants()) do
        disableCollision(obj)
    end
    model.DescendantAdded:connect(function(obj)
        disableCollision(obj)
    end)
end

game:GetService('Players').PlayerAdded:connect(function(player)
    if player.Character then
        setup(player.Character)
    end
    player.CharacterAdded:connect(function(char)
        setup(char)
    end)
end)
for i,v in next, game:GetDescendants() do
    pcall(function() if v:IsA("BasePart") and v.Name == "Handle" then disableCollision(v) end end)
end

This script above should handle most cases, you see all you need to do is loop through instances and use a if statement to check if its a part and its name is "Handle" you then disable said collision.

for i,v in next, game:GetDescendants() do
    pcall(function() if v:IsA("BasePart") and v.Name == "Handle" then disableCollision(v) end end)
end

In case the part was in multiple services I looped through the entire game, I used the pcall because some instances error if you try to do certain things on it, like checking the classname, but it might not be necessary as I could be wrong. Note that this will not cover cloning the handle parts or their ancestors, if its necessary to do so then you must manually do it or use the .DescendantAdded event.

0
lol because i am a very bored person i would simply make a local script in a player making a part cancollide = true while server sidely, part cancollide = false it would work lol Igoralexeymarengobr 365 — 5y
Ad

Answer this question