Creating a wall that only certain players, or a projectile can go through

Hello, I am trying to create a wall in the middle of a court that acts as a barrier to a specific team of players. How would I go about making a wall that when a projectile is thrown at it, it will go through the wall but will not allow players to go through? This is kind of hard to explain so I will add some screenshots

So here is a screenshot of a test court, so notice how there are two sides a red side and blue side. And the middle has two walls that I set slightly transparent so you can see everything better. So the team on the left side (red team) I want to be able to go to the first transparent wall closest to them, and the team on the right side (blue team) I want to go through was first transparent wall also closest to them, but get stopped at the next wall. I also want it so projectiles can go through both of these walls, how would I go about doing this. If you need me to clarify something just ask it was kind of hard to explain lol.

6 Likes

Alright my baseline idea is to use LocalScripts that should make it Client side only, Is that what your going for?

For example:
(local) (round started for example telling the client to open the door)
game.ReplicatedStorage.DoorService:FireServer("Red", "Open")
(server)
game.ReplicatedStorage.DoorService.OnServerEvent(player, door, status)
if door == “Red” and status == “Open” then
game.ReplicatedStorage.DoorClient:FireClient(“Red”, “Open”)
end
end)
(local)
game.ReplicatedStorage.DoorClient.OnClientEvent(door, status)
if status == “Open” and door == “Red” then
game.Workspace:FindFirstChild(“RedDoor”).Transparency = 1
elseif status == “Close” and door == “Red” then
game.Workspace:FindFirstChild(“RedDoor”).Transparency = 0.5
end
end)

3 Likes

That sounds like a pretty good idea so only the player can walk through it, so how exactly would I do this? Would I just get the players team and if the players team is red or blue then make a certain wall can collide?

I’d suggest reading up on the PhysicsService documentation to create collision groups:
Physics Service Documentation

Using collision groups, you can make it so only specific players or objects can travel through objects in a collision group.

2 Likes
(local) (round started for example telling the client to open the door)
    local function checkteam()
    local p = game.Players.LocalPlayer
    if p.Team == game.Teams.Blue then
    game.ReplicatedStorage.DoorService:FireServer("Blue", "Open")
    game.ReplicatedStorage.DoorService:FireServer("Red", "Close")
    else
    game.ReplicatedStorage.DoorService:FireServer("Blue", "Close")
    game.ReplicatedStorage.DoorService:FireServer("Red", "Open")
    end
    end
    while wait(0.5) do
    checkteam()
    end
(server)
    game.ReplicatedStorage.DoorService.OnServerEvent(player, door, status)
    if door == “Red” and status == “Open” then
    game.ReplicatedStorage.DoorClient:FireClient(“Red”, “Open”)
    elseif door == “Red” and status == “Close” then
    game.ReplicatedStorage.DoorClient:FireClient(“Red”, “Close”)
    elseif door == “Blue” and status == “Open” then
    game.ReplicatedStorage.DoorClient:FireClient(“Blue”, “Open”)
    elseif door == “Blue” and status == “Close” then
    game.ReplicatedStorage.DoorClient:FireClient(“Blue”, “Close”)
    end
    end)
(local)
    game.ReplicatedStorage.DoorClient.OnClientEvent(door, status)
    if status == “Open” and door == “Red” then
    game.Workspace:FindFirstChild(“RedDoor”).Transparency = 1
    elseif status == “Close” and door == “Red” then
    game.Workspace:FindFirstChild(“RedDoor”).Transparency = 0.5
    elseif status == “Open” and door == “Blue” then
    game.Workspace:FindFirstChild(“BlueDoor”).Transparency = 1
    elseif status == “Close” and door == “Blue” then
    game.Workspace:FindFirstChild(“BlueDoor”).Transparency = 0.5
    end
    end)

ps I wrote this out of studio mat be some bugs in it, most likely not.

1 Like

You could look into both Collision Filtering and this article on making team restricted doors.

You can use PhysicsService:
StarterCharacterScripts:

local PS = game:GetService("PhysicsService")

local Character = script.Parent

local function Collisions(Part)
    if Part:IsA("BasePart") then
        PS:SetPartCollisionGroup(Part, "Team1")
    end
end

for i, v in pairs(Character:GetChildren()) do
    Collisions(v)
end

Character.DescendantAdded:Connect(Collisions)

ServerScriptService:

local PS = game:GetService("PhysicsService")

PS:CreateCollisionGroup("PassThrough")
PS:CreateCollisionGroup("Team1")

PS:CollisionGroupSetCollidable("PassThrough", "Team1", false)
local Part = --the part that only specific people go through 
PS:SetPartCollisionGroup(Part, "Team1")

Basically what this does is it makes specific parts go through each other

3 Likes

I will look into this, it seems like a great idea! And thanks everybody for the suggestions.