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

Have only certain player(s) have player collisions off?

Asked by 6 years ago

So I'm currently in the process of making a game like "Design It", and in this game everyone teleports to a changing area.

I don't want to create a room for each player so I thought about just making the characters invisible and use collision groups to make them cancollided.

I just can't figure out how to do this properly, basically MOST people will be in the changing area, but I don't understand how to make it so those who AREN"T in the changing room DO have player collisions still.

An example: 7 players are in a room, I want their collisions off. 3 players outside of the room, still should have their collisions

I got no clue how to do this, any help would be appreciated :)

Here is the code I've been using from the wiki:

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)

local previousCollisionGroups = {}

local function setCollisionGroup(object)
    if object:IsA("BasePart") then
        previousCollisionGroups[object] = object.CollisionGroupId
        PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
    end
end

local function setCollisionGroupRecursive(object)
    setCollisionGroup(object)

    for _, child in ipairs(object:GetChildren()) do
        setCollisionGroupRecursive(child)
    end
end

local function resetCollisionGroup(object)
    local previousCollisionGroupId = previousCollisionGroups[object]
    if not previousCollisionGroupId then return end 

    local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
    if not previousCollisionGroupName then return end

    PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
    previousCollisionGroups[object] = nil
end

Answer this question