Team only Proximity Prompts

So in jailbreak they have a pickpocketing system. Prisoners and pickpocket police officers but police officers can’t pickpocket other police officers. What I’m trying to create is a proximity prompt that can only be visible and used by a specific team. I already have scripted the prompt to only be used by a specific team but all I’m trying to do is not make it visible unless your on that specific team.

You can use an if statement on the proximity thing so if they are on the police team it doesn’t show up. For example,

If not police then

[Your proximity thing here]

end

No this is what I mean.


I want this prompt to not be visible to the other team but visible to the chickens team.

If you want it visible to only a specific team, you want to use a local script to check the player’s team and enable the ProximityPrompt if they are on that specific team.
Using a server script will not work properly, because if you enable the ProximityPrompt, it will be enabled to all players no matter what team they are on.

Here is a code example (I suggest you have the Local Script in StarterPlayerScripts):

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

local PP = workspace:WaitForChild("ProximityPrompt") -- locate your ProximityPrompt here

if plr.TeamColor == BrickColor.new("TEAM COLOR HERE") then
	PP.Enabled = true
else
	PP.Enabled = false
end

plr:GetPropertyChangedSignal("TeamColor"):Connect(function()
	if plr.TeamColor == BrickColor.new("TEAM COLOR HERE") then
		PP.Enabled = true
	else
		PP.Enabled = false
	end
end)

2 Likes

You can create proximity prompts on the client. Do this instead of making them on the server.

I use something like this for my matchmaking system, wherein I have a queue prompt.

local proximityPrompt = Instance.new("ProximityPrompt")
proximityPrompt.ObjectText = "Vault"
proximityPrompt.ActionText = "Explode Vault"
proximityPrompt.MaxActivationDistance = 20
proximityPrompt.HoldDuration = 0.33
proximityPrompt.RequiresLineOfSight = false
proximityPrompt.Parent = interaction

Put this in a local script, and verify the player’s team.

local Game = game
local Workspace = workspace
local Teams = Game:GetService("Teams")
local Part = Workspace.Part
local Prompt = Part.ProximityPrompt

local function OnPromptTriggered(Player)
	if Player.Team ~= Teams["Red Team"] then return end --If player is not a member of the red team ignore the triggered prompt.
	--Do code.
end

Prompt.Triggered:Connect(OnPromptTriggered)
2 Likes

Most of the replies you got covered the basics of what you’re trying to achieve but I would like to propose another idea that is a little more developer-friendly on large scale projects: CollectionService.

You can tag every ProximityPrompt that is intended to be team-only and then iterate through them in a LocalScript to apply the team-only logic more efficiently.

1 Like

The way I would go about doing this, I would create the ProximityPrompt’s either on the server or the client.

When the proximity prompt is activated:


local ProximityPrompt = game:GetService("Workspace").Vault.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(player)
      if player.Team == game:GetService("Teams").Criminal then
          openDoor(ProximityPrompt.Parent)
      end
end)

On the client, you need to use this code:


repeat task.wait() until game:IsLoaded()
local ProximityPrompt = game:GetService("Workspace").Vault.ProximityPrompt

local teamEvent = function()
     if player.Team == game:GetService("Teams").Criminal then
         ProximityPrompt.Enabled = true
     else
         ProximityPrompt.Enabled = false
     end
end

teamEvent()

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
    teamEvent()
end)

If you wanted to do multiple prompts, you could parent all pats with only criminal proximity prompts a folder, like this:


repeat task.wait() until game:IsLoaded()
local Prompts = game:GetService("Workspace").Criminal

local teamEvent = function()
    for i,v in pairs(Prompts:GetDescendants()) do
        if v:IsA("ProximityPrompt") then
            if game.Players.LocalPlayer.Team == game:GetService("Teams").Criminal then
                v.Enabled = true
            else
                v.Enabled = false
            end
        end
    end
end

teamEvent()

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
   teamEvent()
end)

This method is exploiter-proof, as it checks on the server and also the most efficient way to do this.