Proximity Prompt inside Player not Enabling

Hiya!

Im attempting to make a tool that makes proximity prompts enable on other players when the player holding the tool equips it, So long as it meets these requirements:

  1. They’re within a set distance.
  2. They’re the closest player to the player holding the tool.

Im running this through two scripts, A serverscriptservice script that creates the prompts:

--[[ Vairables ]]--
local players = game:GetService("Players")

--[[ Functions ]]--
function AddProxPrompt(character)
	local ArrestPrompt = Instance.new("ProximityPrompt")
	ArrestPrompt.ActionText = ""
	ArrestPrompt.ObjectText = ""
	ArrestPrompt.Name = "ArrestPrompt"
	ArrestPrompt.MaxActivationDistance = 1000
	ArrestPrompt.HoldDuration = 1
	ArrestPrompt.Enabled = false 
	ArrestPrompt.Parent = character:WaitForChild("HumanoidRootPart")
end

--[[ Player Added ]]--
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		AddProxPrompt(character)
	end)
end)

And a local script inside the tool:

--[[ Variables ]]--
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Tool = script.Parent

--[[ Functions ]]--
function findClosestPlayer()
	local character = Player.Character
	if not character then
		return nil
	end

	local toolPosition = Tool.Handle.Position

	local closestPlayer = nil
	local closestDistance = 10 -- Change this value to your desired radius

	for _, otherPlayer in pairs(Players:GetPlayers()) do
		if otherPlayer ~= Player then
			local otherCharacter = otherPlayer.Character
			if otherCharacter and otherCharacter:FindFirstChild("HumanoidRootPart") then
				local distance = (toolPosition - otherCharacter.HumanoidRootPart.Position).Magnitude
				if distance < closestDistance then
					closestPlayer = otherPlayer
					closestDistance = distance
				end
			end
		end
	end

	return closestPlayer
end

function ShowPrompt()
	local ClosestPlayer = findClosestPlayer()
	if ClosestPlayer and ClosestPlayer.Character:WaitForChild("HumanoidRootPart"):FindFirstChild("ArrestPrompt") then 
		local prompt = ClosestPlayer.Character:WaitForChild("HumanoidRootPart"):FindFirstChild("ArrestPrompt") 
		prompt.Enabled = true
	end
end

--[[ Equipped ]]--
Tool.Equipped:Connect(function()
	while true do 
		wait(0.5)
		ShowPrompt()	
	end
end)

The Issue:
Everything seems to work, it’s properly detecting the other player yet whenever it tries to enable the prompt it doesn’t become visible for the user holding the tool. Any idea on how I could fix this?

1 Like

Ironically, I am currently in the stages of developing handcuffs but - I may be wrong here - the problem is how the local script is interacting. The local script can see what is inside of players. But cannot change any data in them. This is to do with Network Ownership

Ah, I see. Do you have any recommendations on how I could fix this?

Turn off RequiresLineOfSight when setting up the prompt.

2 Likes

This solved the issue! Thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.