Using Proximity Prompts to Arrest Players

Hello there, fellow developers. Today I have made a proximity prompt that should only show to the police, but I’ve been having trouble with the team-wide stuff. It works perfectly with the police side, but non-police players suddenly have the option to arrest each other.
robloxapp-20220412-1554243.wmv (1.2 MB)
As you can see, I am a civilian but can arrest other civilians. I have looked everywhere for a solution and can’t find one that would work. Here are my scripts:
Local script in Workspace:

game.ReplicatedStorage.ArrestProximityPrompt.OnClientEvent:Connect(function(player)
	local proxPrompt = player.Character.HumanoidRootPart.ArrestProximityPrompt
	if game.Players.LocalPlayer.Team.Name ~= "Police" then
		proxPrompt.Enabled = false
	else
		proxPrompt.Enabled = true
	end
end)

Script in Workspace:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player) -- connects to a function when a player joins, with a player variable

local proxPrompt = Instance.new("ProximityPrompt")

player.CharacterAdded:wait() -- waits for character to prevent "attempt to index nil with character" error

proxPrompt.Parent = player.Character:WaitForChild("HumanoidRootPart") -- parents the proxprompt instance to humanoidrootpart

proxPrompt.ObjectText = "Player"

proxPrompt.ActionText = "Arrest"

proxPrompt.HoldDuration = 1

proxPrompt.Name = "ArrestProximityPrompt"

proxPrompt.RequiresLineOfSight = false

game.ReplicatedStorage.ArrestProximityPrompt:FireClient(player)

end)

Thanks,
SpeakerDev and Team

1 Like

Firstly, I would say it’s better practice to have your local script in StarterPlayerScripts. But that’s just me.

Also, you would do better to use CustomUI for the Proximity Prompt in this scenario IMO.

What you’ve done effectively is your ArrestProximityPrompt remote event is only being fired to the client that has joined the game, so obviously it’s not going to work on everyone else, the issue you would then have arise however even if you use :FireAllClients() is that players that join the game after that player, would still see their Proximity Prompt.

I think you would do better to use CustomUI that only shows for police - or - disable the proximity prompt service for non-police, depending on how you are utilising ProximityPrompt in your game.

1 Like

How would I disable the ProximityPrompt for everyone? If i just do

proxPrompt.Enabled = false

it would only apply to that one client and not every client. And it has to be inside a LocalScript or it wouldn’t show up for anyone, including the police.

Thanks,
SpeakerDev and Team

I made a handcuff system that welds the player to another player. I did this by putting a server script in the handcuff tool and detecting all triggered proximity prompts, we check if the tool is equipped by doing “local toolEquipped = tool.Parent:IsA(“Model”)” this works because if the player equippes a tool the tools parent is gonna be the character (which is a model) so that will return a true or false value. We now know if the tool is equipped and who triggered the proximity prompt. We also need a variable at the start of the code that is as followed “local currentLEO = tool.Parent.Parent” so that is the player, now we need to know if there is noone already captured and if the prompts name is for example “HandcuffPrompt” one last variable, the captured player and that is very simple to do, because that is “local capturedPlayer = players:GetPlayerFromCharacter(prompt.Parent.Parent)” so then you end up with: “if prompt.Name == “HandcuffPrompt” and player ~= capturedPlayer and toolEquipped and not captured and player == currentLEO then” I made this a module "-- Help with welding player to player



local playerWeld = {}

local ps=game:GetService("PhysicsService")

ps:RegisterCollisionGroup("23637Lh84wfGzr26")
ps:CollisionGroupSetCollidable("23637Lh84wfGzr26","23637Lh84wfGzr26",false)

playerWeld.weldPlayers = function(origin,carry)
	local ro,rc=origin.Character.PrimaryPart,carry.Character.PrimaryPart
	carry.Character.Humanoid.PlatformStand=true
	local w=Instance.new("Weld")
	w.Name="__CARRYWELD"
	w.Part0=rc
	w.Part1=ro
	w.C1=CFrame.new(0, 0, -1.75)
	w.Parent=rc
	for _,v in pairs(carry.Character:GetChildren()) do
		if v:IsA("BasePart") then
			ps:SetPartCollisionGroup(v,"23637Lh84wfGzr26")
			v.Massless=true
		end
	end
	for _,v in pairs(origin.Character:GetChildren()) do
		if v:IsA("BasePart") then
			ps:SetPartCollisionGroup(v,"23637Lh84wfGzr26")
		end
	end
end

playerWeld.restorePlayer = function(plr)
	local char = plr.Character
	char.Humanoid.PlatformStand=false
	if char.PrimaryPart:FindFirstChild("__CARRYWELD") then
		char.PrimaryPart:FindFirstChild("__CARRYWELD"):Destroy()
	end
	for _,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("BasePart") then
			v.CollisionGroupId=0
			v.Massless=false
		end
	end
end

return playerWeld" and now we just do this “playerWeld.weldPlayers(player, capturedPlayer)” I hope that helps, i am not that good at explaining stuff but i hope that helps you. If you need any help you can just ask.