Pickpocketing System Bug

I just finished making a pickpocket system for my roblox prison game, it’s working fine but there’s 1 bug, I never found a way how to make it to where you can’t see the proximity prompt on your back, nor other police officers, so you can see the proximity prompt on your back and same with the other officers? Why is this bothering me? Just look for yourself.
image
It’s always just on your screen, is there a way to make it to where the proximity prompt is NOT visible to the police team and only the rest of them?

I forgot to say, here’s the code.

local ProximityPrompt = game.ReplicatedStorage.PickpocketPolice

game.Players.PlayerAdded:Connect(function(plr) 
	plr.CharacterAdded:Connect(function(char)
		local Proximity = ProximityPrompt:Clone()
		Proximity.Parent = char
		while true do
			wait()
			if plr.TeamColor == BrickColor.new("Lapis") then
				Proximity.Enabled = true
			else
				Proximity.Enabled = false
			end
		end
	end)
end)

new local script:

local ProximityPrompt = game.ReplicatedStorage.PickpocketPolice
local Players = game:GetService("Players")
local Teams  = game:GetService("Teams")

local Player = Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(plr)
	if plr == Player then return end
	
	plr.CharacterAdded:Connect(function(char)
		local Proximity = ProximityPrompt:Clone()
		Proximity.Parent = char
		if plr.Team == Teams.Police then
			Proximity.Enabled = true
		else
			Proximity.Enabled = false
		end
	end)
end)

Local script right?

[adding this for the extra characters to reach 30]

yes, add it on starter player scripts, and delete the current script

1 Like

Alright thank you! I’ll let you know if there’s any bugs.

It didn’t work? I got my friend who was on the criminal team to come to me and he said nothing was there.

It looks like you’re enabling it only for the police team, so maybe that’s why the criminals can’t see it

The code is checking if they’re on the police team, and if they are, the proximity prompt that was cloned into their back when they joined will enable, originally everyone could see it [which I didn’t like and I was trying to make it to where the police couldn’t see it, only the other teams], but with @BirdieI90’s fix, it’s not working whatsoever.

Ohh, ok. Sorry for my misunderstanding.

Try this. The code sent by BirdieI90 seems like it would work, are there any error present? I also recommend putting this in ReplicatedStorage rather than StarterPlayerScripts. Make sure this is a LocalScript as well.

One potential issue I see is if a player changes teams to Police they will still have the prompts for other policeman present, meaning you will most likely need to use a RemoteEvent to disable any prompts in police characters after a team change.

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

local LocalPlayer = Players.LocalPlayer

local ProximityPrompt = game:GetService("ReplicatedStorage"):WaitForChild("PickpocketPolice")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local NewProximity = ProximityPrompt:Clone()
        NewProximity.Enabled = LocalPlayer.Team ~= Teams.Police and Player ~= LocalPlayer and Player.Team == Teams.Police
        NewProximity.Parent = Character
    end)
end)

I would also put the code that handles the prompts in StarterPlayerScripts, if it isn’t there already.

That doesn’t fix the problem, the proximity prompt would still be visible for the police, meaning the proximity prompt pickpocket on their back would be bothering them the whole time.

--CLIENT

local Game = game
local Players = Game:GetService("Players")
local Teams = Game:GetService("Teams")
local LocalPlayer = Players.LocalPlayer
local RedTeam = Teams:WaitForChild("RedTeam")

local function OnPlayerTeamChanged()
	for _, Player in ipairs(RedTeam:GetPlayers()) do
		local Character = Player.Character
		if not Character then continue end
		local ProximityPrompt = Character:FindFirstChildOfClass("ProximityPrompt")
		if ProximityPrompt then ProximityPrompt.Enabled = (LocalPlayer.Team ~= RedTeam) end
	end
end

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		if Player.Team ~= RedTeam then return end
		local ProximityPrompt = Character:WaitForChild("ProximityPrompt", 5)
		if ProximityPrompt then ProximityPrompt.Enabled = (LocalPlayer.Team ~= RedTeam) end
	end
	
	Player.CharacterAdded:Connect(OnCharacterAdded)
	local Character = Player.Character
	if Character then OnCharacterAdded(Character) end
end

LocalPlayer:GetPropertyChangedSignal("Team"):Connect(OnPlayerTeamChanged)
Players.PlayerAdded:Connect(OnPlayerAdded)
for _, Player in ipairs(Players:GetPlayers()) do
	OnPlayerAdded(Player)
end

I’m not quite sure how I’m supposed to use this…?? It doesn’t have anything in the code that’ll clone the proximity prompt from replicated storage, and that code you made is extremely advanced for me so I don’t know how I’m supposed to add that in, and I can’t tell if the variable “RedTeam” refers to the Criminal team, or the Police team. It also doesn’t say where to put it in my game, would it be possible if you could code in the clone part, and say where to put it?