How to make a prompt only appear for one player

I made this script below which detects if a player owns a gamepass in order for a prox. prompt to appear for that player only. However, the script is making it appear for everyone else if one person meets the ``if``` requirement. Is there a way someone can help me alter the script so this only works for that one player that meets the requirements?

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

local BCSO_TEAM = Teams.BCSO
local OPD_TEAM = Teams.OPD

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 28301022) and Player.Team == OPD_TEAM then
			script.Parent.Enabled = true
		end
	end)
end)

I know only one way.
1 Make local script in StarterGui

2 Copy and paste in your local script


wait(2)

local Player = game.Players.LocalPlayer
local OPD = game.Teams.OPD
local MarketplaceService = game:GetService("MarketplaceService")
if game.Players.LocalPlayer.Team == OPD and MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 28301022) then

	local prox = Instance.new("ProximityPrompt", game.Workspace.l1)     -- change game.workspace.l1 to your localization
	prox.ActionText = "text"
	prox.ObjectText = "text"
	prox.ClickablePrompt = true
	prox.HoldDuration = 0
end

Only player who is in team and has gamepass see proximity prompt.

Thanks! I’ll test this out later.

This is easily exploitable, use remoteevents to fire an event to the certain player.

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

local BCSO_TEAM = Teams.BCSO
local OPD_TEAM = Teams.OPD

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 28301022) and Player.Team == OPD_TEAM then
			RemoteEvent:FireClient(Player)
		end
	end)
end)

I replace this with the code, and there is a red line under “RemoveEvent”…

Of course it wud have a red line, I gave you prototype code, not an entire script. For your sake, I will complete it here:

Prerequisites:

  1. Place a RemoteEvent named “PromptEvent” in ReplicatedStorage
  2. A server script
  3. A local script parented to a ProximityPrompt

Code:
In server script:

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

local BCSO_TEAM = Teams.BCSO
local OPD_TEAM = Teams.OPD
local RE = ReplicatedStorage:WaitForChild("PromptEvent")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 28301022) and Player.Team == OPD_TEAM then
			RE:FireClient(Player)
		end
	end)
end)

In localscript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RE = ReplicatedStorage:WaitForChild("PromptEvent")

--// Events
RE.OnClientEvent:Connect(function()
    script.Parent.Enabled = true
end)

That local script’s reference to the ProximityPrompt instance will need to change (assuming the prompt is in the workspace).

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("PromptEvent")
local Part = workspace:WaitForChild("Part")
local Prompt = Part:WaitForChild("ProximityPrompt")

--// Events
RE.OnClientEvent:Connect(function()
	Prompt.Enabled = true
end)

The script would go inside “StarterPlayerScripts”.

1 Like

Well, that was my initial thought but the OP had the localscript parented to the prompt, so i didn’t want to confuse him

1 Like

Yeah, if the thread’s poster gets this working I recommend that he gives the solution mark to you.

1 Like