How can I make a proximpty prompt appear on the player?

I’ve recently been working on a new game, and needed some help with making a prompt appear on a player.

Not much to work with, but if you mean positioning wise, then parent the prompt to the player’s HumanoidRootPart

I basically need it so when a player joins, another player can see a prompt on their humanoidrootpart that is basically a request to “Pair up” with them.

Okay, Then use PlayerAdded(plr) on Game.Players to detect when a player joins, and then use CharacterAdded on the plr that just joined, and then wait for their humanoidRootPart, and then add the prompt in.

That will show the button for the player too though. If you only want the prompt to appear for other people, make a remote event and fire it once you added the prompt. In the remote event, you want to include the player and the prompt as parameters. Then, make a client side script in startercharacterscripts, and check for an OnClientEvent. Then, using the parameters from the server-side script, just set prompt.Enabled to false.

It was an example, not the exact way to do it, i dont know what specific type of game the OP is making.

This worked, although the prompt only appears on your own player, and not on another player.

Did you make it a server-side script?

if you’re doing it via local script, make it a Server script in ServerScriptService.

I have two scripts, one in serverscriptservice (Server Script)

`local Players = game:GetService(“Players”)
local ProximityPromptService = game:GetService(“ProximityPromptService”)

local remoteEvent = Instance.new(“RemoteEvent”)
remoteEvent.Name = “PairUpPromptEvent”
remoteEvent.Parent = game.ReplicatedStorage

local function UpdatePairUpPrompt(targetPlayer)
local character = targetPlayer.Character
if not character then
character = targetPlayer.CharacterAdded:Wait()
end

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local prompt = humanoidRootPart:FindFirstChild("PairUpPrompt")
if not prompt then
	prompt = Instance.new("ProximityPrompt")
	prompt.ActionText = "Pair Up"
	prompt.ObjectText = "Press E to Pair Up"
	prompt.Name = "PairUpPrompt"
	prompt.Parent = humanoidRootPart
end

prompt.Triggered:Connect(function(player)
	remoteEvent:FireClient(player, targetPlayer, prompt)
end)

prompt.DistanceToTrigger = 5 

end

Players.PlayerAdded:Connect(function(player)
UpdatePairUpPrompt(player)
end)`

And one in StarterPlayerScripts (LocalScript)

`local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage:WaitForChild(“PairUpPromptEvent”)

remoteEvent.OnClientEvent:Connect(function(targetPlayer, prompt)
local player = game.Players.LocalPlayer
if player ~= targetPlayer then
prompt.Enabled = false
end
end)`

To add on, I’m not very good at scripting so this isn’t a usual thing id do.

ok don’t make the remote event with a script that’s just unnecesarry

None the less, i think remote events are very useless in this case.
Your system should just make so when a player joins, the server will add a prompt to them, then the client can detect if their humanoidrootpart had a childadded event, if so, then hide the prompt (there is probably a better way to do this, but this is just an example)

edit: i re-read the script and i think (?) that you’re trying to make the prompt go invisible when paired up, you dont need a remote event for that, just make it invisible in general so no other players can pair up while you are already paired.

What im essentially trying to get is something like this system in the game Alitorture, where you can pair up with a player and it’d connect you both with a rope (I don’t need this, just the pair up system)

Here:

--SERVER SIDE
local remote = game.ReplicatedStorage:WaitForChild("<remoteevent>")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local prompt = Instance.new("ProximityPrompt",character:WaitForChild("HumanoidRootPart")
remote:FireClient(player,prompt)
end)
end)

--CLIENT SIDE
local remote = game.ReplicatedStorage:WaitForChild("<remoteevent>")
remote.OnClientEvent:Connect(function(prompt)
prompt.Enabled = false
end)

Okay, Then don’t use a remote event, You should just disable the prompt visibility on everyone’s screen, so do that on the server, same goes for the rope.

Here’s what i would do (this is an example)

Local promptbase = game.ReplicatedStorage.PromptBase

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local proxprompt = promptbase:Clone()
proxprompt.Parent = char:WaitForChild("HumanoidRootPart")
proxprompt.Activated:Connect(function(plrthatinteracted)
print(plrthatinteracted.Name.. " Paired up with " .. plr.Name)
end)
end)

Activated might be the wrong name for the event, i havent used prompts in a while, so i dont remember the function to detect when interacted with’s name.

If you wanted to make a script that creates and parents a ProximityPrompt to every player that joins the game, you could use the following guide:

Create a server-side script then place it in ServerScriptService in the Explorer, then paste in the following code:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local prompt = Instance.new("ProximityPrompt")
		prompt.ObjectText = player.Name
		prompt.ActionText = "Pair Up"

		prompt.Parent = character

		prompt.Triggered:Connect(function(playerRequestingPair)
			print(playerRequestingPair, "is requesting to pair with", player.Name)
		end)
	end)
end)

From this point you have a script that will create a new ProximityPrompt for every player that joins. But, that also means that the instance has been replicated over to the client. This means that the player can interact with their own prompt, possibly breaking the game.

We will create a client side LocalScript that will call :Destroy() on the player’s prompt, so this does not happen.

Create a new LocalScript and parent it to StarterPlayerScripts, then open the script and paste this code:

game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function(character)
	local prompt: ProximityPrompt = character:WaitForChild("ProximityPrompt")
	prompt:Destroy()
end)

Since the ProximityPrompt is created on the server the prompt will be replicated onto the client, which guarantees that it will always be destroyed for the player.

In comparison to other possible methods of doing this, I believe this is most performant for your use case based on the simplicity and easy-to-use structure it follows.

I hope this helped, reply if you have questions!

How about adding the prompt when a player joins, but only on other players clients, parenting it to the newcomer’s HumanoidRootPart using a local script (on other clients) so they see the prompt, but not the newcomer?

Pairing up wouldn’t work then, since it only appears for other players, therefore the server can not check for pairing up, unless you use remote events.

good solution, i bet it will help the OP. Nice job with it!