Proximity Prompt on Handcuffs

image

Hi,

I am trying to make an arrest system that works basically like Jailbreak’s. Instead of using my outdated interact system, I tried ProximityPrompt for the first time. The issue I have with ProximityPrompt is that the prompt appears to everyone, including the criminal himself. The way to proceed to fix that is through local scripts, however I have absolutely no clue on how to even start with that despite my research.

The requirements for the proximity to pop up would be:

  • Police Team
  • Has handcuffs equipped

If anyone could give me a quick explanation on how I should go about it, it would be much appreciated.

Thanks in advance!

3 Likes

Idk how you would code this to work when you go to a player but could you put a proximity prompt in the handcuffs and place that in replicated storage and then parent it to the players inventory thing if they’re on the police team?

Well, depending on how you could implement this you can set a ProximityPrompt to all Targets, and create one if they don’t already have 1 set up on their parent perhaps

You’d also need to set up a RemoteEvent so that you’re able to cuff the Target on the server-side

local RepStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

local Event = RepStorage:WaitForChild("RemoteEvent")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart") --This is to ignore the LocalPlayer's HRP upon looping

Tool.Equipped:Connect(function()
    if Player.TeamColor == Teams.Officer.TeamColor then

        for _, Part in pairs(workspace:GetChildren()) do
            local Prompt
            local RootPart = Part:FindFirstChild("HumanoidRootPart")
            if RootPart then
                if RootPart:FindFirstChild("ProximityPrompt") == nil then
                    Prompt = Instance.new("ProximityPrompt")
                    Prompt.ActionText = "Arrest"
                    Prompt.Parent = RootPart
                elseif RootPart:FindFirstChild("ProximityPrompt") then
                    Prompt = RootPart.ProximityPrompt
                end

                Prompt.Triggered:Connect(function()
                    Event:FireServer()
                end)
            end
        end

    end
end)

I suppose this could be 1 approach of handling it, but it’s a bit tight on how you wanna make it work

2 Likes

Do I have to remake the same loop inside an unequipped function if I wanna make sure that the prompts don’t appear when I unequip the tool?

Yeah, but again it depends on how you want to make it work

If you already have NPC’s set up, you could just detect if they simply have a ProximityPrompt on them, then set its Enabled property to false when you unequip the tool which would be a much easier approach since you could set it back to true when the tool gets re-equipped

1 Like

Another question I have from reading the code would be if I equip the tool 3 times before using it on someone, will the event trigger three times? How would I prevent that?

Yeah, the Equipped & Unequipped Events would fire every time the tool gets equipped/unequipped

Sadly I don’t believe there’s a way of preventing this, since if you’re wanting to update it for players as well you’d need to loop through everything

Or you could potentially strict things down by placing the NPC’s & Players inside a Folder to reduce performance while firing your loop

I just thought about a solution. If I destroy the prompts and create new ones everytime I equip the tool, the trigger would only fire once.

You could do that

You could also set the Enabled property to false after you trigger the event, depending on how you want to do it (Teleporting the NPC would maybe be the best example if you want to sent the NPC to jail instantly after holding the prompt)

I know this is late, but i managed to make a full arrest system with proximity prompts that doesnt use remotes

1 Like