How would i make a proximity prompt only for certain teams

Hello everyone I have a robbery system in my game that uses a proximty prompt and I would like to ask if I can make the prompt only visible to civs and criminals and other teams.bc police or any leo team can rob it and get the cash

1 Like

Simple example here.

1 Like

This can be achieved by only enabling the prompt on the client. You should make the proximity prompt disabled by default on the server by setting “Enabled” to false. Next, create a remote event that will be responsible for telling a client to enable the prompt. You can then fire the remote event to every player that are in the criminals team,etc.

Example Server code:

local Players = game:GetService("Players")
local Teams = Game:GetService("Teams")

local prompt = --path to your prompt
prompt.Enabled = false

local PromptEvent = --The path to your remote event


local function UpdatePlayersPromptVisibility() --You can hook this function to an event or whatever
    for _,plr in pairs(Players:GetPlayers()) do
        if plr.Team ==  Teams["The Name Of The Team You Want To See The Prompt"] then
             PromptEvent:FireClient(v, true)
        else
             PromptEvent:FireClient(v, false)
        end

       

    end

end

Example Client code

local PromptEvent = --the path to your remote event
local prompt = --path to your prompt

PromptEvent.OnClientEvent:Connect(function(status)
    prompt.Enabled = status
end)
1 Like

what about multiple prompts how would that work

You can achieve that by simply making the prompt a table like this:

Example Server code:

local Players = game:GetService("Players")
local Teams = Game:GetService("Teams")

local prompts = {} --Put in the prompts you want (Example: {workspace.p1.Prompt,workspace.p2.Prompt, etc})

for _,v in ipairs(prompts)
   v.Enabled = false
end

local PromptEvent = --The path to your remote event


local function UpdatePlayersPromptVisibility() --You can hook this function to an event or whatever
    for _,plr in pairs(Players:GetPlayers()) do
        if plr.Team ==  Teams["The Name Of The Team You Want To See The Prompt"] then
             PromptEvent:FireClient(v, prompts, true)
        else
             PromptEvent:FireClient(v, prompts, false)
        end

       

    end

end

Example Client code:

local PromptEvent = --the path to your remote event

PromptEvent.OnClientEvent:Connect(function(prompts, status)
   for _,v in ipairs(prompts)
      v.Enabled = status
   end   
end)

Also in the code that handles the prompt(s) being interacted with, I suggest you do safety checks to make sure the player clicking it is in the correct team since there’s nothing stopping an exploiter from enabling the prompt on their client. Example of checking if the player is in the right team:

“if player.Team ~= The Name Of The Team You Want The Prompts Enabled for then return end”

Tell me if that works for you!

1 Like

In the past, for the same thing, I have used local scripts for each team to do this. Use remote events and :FireClient() to only the specific members of that team. Then when you fire the client, have the function create a new proximity prompt. Here is an example:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") -- you should name the remote event more specifically
local ProximityPromptService = game:GetService("ProximityPrompt")
local newPrompt
function createPrompts()
    newPrompt = Instance.new("ProximityPrompt")
    newPrompt.Parent = PartToRob -- PartToRob is just whatever part you want to parent this prompt
    -- create as many prompts as you want
    -- change settings of proximity prompt(s)
end

RemoteEvent.OnClientEvent:Connect(createPrompts)

newPrompt.Triggered:Connect(function()
    RemoteEvent:FireServer()
end)
1 Like

But then how would the server know when the player triggered the prompt since the prompt is created on the client

Sorry, let me fix that. I didn’t realize that it was part of the question.

Can you use multiple teams with that code?