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

How to allow RPlayers into RDoors ????

Asked by 2 years ago
local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("BDoorsGrp")
ps:CreateCollisionGroup("RDoorsGrp")
ps:CreateCollisionGroup("BPlayersGrp")
ps:CreateCollisionGroup("RPlayerssGrp")

local bDoors = workspace.BDoors:GetChildren()
local rDoors = workspace.RDoors:GetChildren()

local function setDoorColGrp(doorTbl, group)
    for i=1, #doorTbl, 1 do
        ps:SetPartCollisionGroup(doorTbl[i], group)
    end
end

setDoorColGrp(bDoors, "BDoorsGrp")
setDoorColGrp(rDoors, "RDoorsGrp")

local function setPlayerColGrp(char, group)
    for i, child in ipairs(char:GetChildren()) do 
        if child:IsA("BasePart") then
            ps:SetPartCollisionGroup(child, group)
        end
    end
    char.DescendantAdded:Connect(function(desc)
        if desc:IsA("BasePart") then 
            ps:SetPartCollisionGroup(desc, group)
        end
    end)
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function(char)
        if player.Team.Name == "Blue" then
            setPlayerColGrp(char, "BPlayersGrp")
        else
            setPlayerColGrp(char, "BPlayersGrp")
        end
    end)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)
ps:CollisionGroupSetCollidable("BDoorsGrp", "BPlayersGrp", false)
ps:CollisionGroupSetCollidable("RDoorsGrp", "RPlayersGrp", false)

How do I make where RPlayers (Red Team) can collide with RDoors?

1 answer

Log in to vote
0
Answered by 2 years ago

I think the best approach would be to check the players team and set the door collisions on the client.

In a local script in StarterCharacterScripts

Code example:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local bDoors = workspace.bDoors
local rDoors = workspace.rDoors

local function setSolid(doors, isSolid)
    for _, door in pairs(doors:GetChildren()) do
        door.CanCollide = isSolid
    end
end

local function InitializeDoors()
    if player.Team.Name == "Blue" then
        setSolid(bDoors, false)
        setSolid(rDoors, true)
    elseif player.Team.Name == "Red" then
        setSolid(rDoors, false)
        setSolid(bDoors, true)
    end
end
player:GetPropertyChangedSignal("Team"):connect(InitializeDoors)
InitializeDoors()
Ad

Answer this question