Disable Proximity Prompt for specific players

I have made a reviving system and everything in the script works. However, I do need to add some elements into the script that I do not know how to do. I have implemented a line that will disable the Proximity Prompt for the player who was knocked out so they cannot recover themselves, the issue is that knocked out player can still recover each other because they can see each others Prompts.

ServerScript (ServerScriptService):

local RS = game:GetService("ReplicatedStorage")
local BE = RS.ReviveBE
local KnockedAnim = script:WaitForChild("KnockedAnim")

local BBG = game.ServerStorage.BillboardGui
--local BBGE = game.ReplicatedStorage.RemoteEvents.BillboardGuiEvent
local BBGF = RS.RemoteFunctions.BillboardGuiFunction
local BBGE = RS.BindableEvents.BBGBE

local ReviveSound = script.ReviveSound

local Players = game:GetService("Players")

local Timer = 30

local revivePrompt = game.ServerStorage.RevivePrompt
local showPrompt = RS.RemoteEvents.ShowPrompt

--local CC = RS.ColorChanger
--local CC2 = RS.ColorChanger2
local CC = RS.BindableEvents.ColorChangerBindableEvent
local CC2 = RS.BindableEvents.ColorChanger2BindableEvent

local knocked = false

local TimerPaused = false
local StopTimer = false

BE.Event:Connect(function(playerThatWasHit)
	wait(0.5)
	print("Player was hit:", playerThatWasHit)
	local Humanoid = playerThatWasHit.Character and playerThatWasHit.Character:FindFirstChild("Humanoid")
	if Humanoid then
		if knocked == false then
			knocked = true
			
			Humanoid.WalkSpeed = 8
			local KAP = Humanoid.Animator:LoadAnimation(KnockedAnim)
			KAP:Play()

			local ClonedBBG = BBG:Clone()
			ClonedBBG.Parent = Humanoid.Parent.Head
			local ClonedRP = revivePrompt:Clone()
			--for _, player in ipairs(Players:GetPlayers()) do
				--print("Don't Display The ProximityPrompt")
				--wait(.1)
				--if player ~= playerThatWasHit then
			ClonedRP.Parent = Humanoid.Parent.UpperTorso
					--ClonedRP.ActionText = "Recover " ..playerThatWasHit.name
				--end
			--end
			
			showPrompt:FireClient(playerThatWasHit, ClonedRP, false, false)

			local function startTimer()
				local remainingTime = Timer

				while remainingTime > 0 do
					if TimerPaused == false then
						if StopTimer == false then
							BBGE:Fire(remainingTime)
							wait(1)
							remainingTime -= 1
							print(remainingTime)
							if remainingTime <= 0 then
							Humanoid.Health = 0
							print("Timer ran out, Humanoid died")
							ClonedBBG:Destroy()
							ClonedRP:Destroy()
							end
						else
							print("Timer Stopped")
							StopTimer = false
							break
						end
					else
						print("Timer Paused")
						wait(1)
					end
				end
			end
			local TimerCoroutine = coroutine.create(startTimer)
			coroutine.resume(TimerCoroutine)

			ClonedRP.Triggered:Connect(function()
				KAP:Stop()
				Humanoid.WalkSpeed = 16
				ReviveSound:Stop()
				StopTimer = true
				task.wait(0.1)
				ClonedRP:Destroy()
				ClonedBBG:Destroy()
				knocked = false
				print("PromptTriggered")
				for _, part in ipairs(playerThatWasHit.Character:GetDescendants()) do
					if part:IsA("BasePart") then
						part.CanCollide = true
					end
				end
			end)

			ClonedRP.PromptButtonHoldBegan:Connect(function()
				ReviveSound:Play()
				CC:Fire()
				print("Begining Hold")
				TimerPaused = true
			end)

			ClonedRP.PromptButtonHoldEnded:Connect(function()
				ReviveSound:Stop()
				CC2:Fire()
				print("Stopped Holding")
				TimerPaused = false
			end)
		else
			return
		end
	end
end)

LocalScript (StarterCharacterScripts):

local replicatedstorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local showPrompt = replicatedstorage.RemoteEvents.ShowPrompt
local promptsToBeHidden = {}

showPrompt.OnClientEvent:Connect(function(prompt, visibility, hideOnRemove)
	prompt.Enabled = visibility

	if hideOnRemove then
		local foundPrompt = table.find(promptsToBeHidden, prompt)
		if foundPrompt == nil then
			table.insert(promptsToBeHidden, prompt)
		end
	end

	if visibility == false then
		local foundPrompt = table.find(promptsToBeHidden, prompt)
			if foundPrompt ~= nil then
				table.remove(promptsToBeHidden, foundPrompt)
		end
	end
end)

Players.LocalPlayer.CharacterRemoving:Connect( function ()
	for i, prompt in promptsToBeHidden do
		if prompt then
			prompt.Enabled = false
		end
	end
	promptsToBeHidden = {}
end)
1 Like