ProximityPrompt Issue

Hello!
I have a little problem with ProximityPrompt because I made a script that print("A") when it triggers etc. but the problem is that if I turn Enabled off and on, it sends triggered twice. I tried to fix it myself but it didn’t work out so I reached out for help here. I hope someone will help :slight_smile:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(0.35)

local Beam = Instance.new("Beam")
local Attachment0 = Instance.new("Attachment")
local Attachment1 = Instance.new("Attachment")
local ProximityPrompt = Instance.new("ProximityPrompt")

local Info = Player:WaitForChild("PlayerInformation")
local Distance = Info:WaitForChild("Distance")
local HoldingDuration = Info:WaitForChild("HoldingDuration")

local Cooldown = 5
local Debounce = true

local ThingsToHack = require(game.ReplicatedStorage.Hacked)

function OnNear(closestPart)
	Attachment1.Parent = closestPart
	Attachment1.CFrame = closestPart.CFrame:ToObjectSpace(HumanoidRootPart.CFrame)
	local PlrToBasePart = TweenService:Create(Attachment1, TweenInfo, {CFrame = CFrame.new()})
	Attachment0.Parent = HumanoidRootPart
	ProximityPrompt.Parent = closestPart
	ProximityPrompt.Enabled = true
	Beam.Parent = HumanoidRootPart
	Beam.Attachment0 = Attachment0
	Beam.Attachment1 = Attachment1
	PlrToBasePart:Play()
	Beam.LightEmission = 1
	Beam.LightInfluence = 1
	Beam.Segments = 100
	Beam.FaceCamera = true
	Beam.Width0 = 0.1
	Beam.Width1 = 0.1
	Beam.Transparency = NumberSequence.new{
		NumberSequenceKeypoint.new(0,1),
		NumberSequenceKeypoint.new(0.0689,1),
		NumberSequenceKeypoint.new(1,0)
	}
	ProximityPrompt.ActionText = closestPart.Parent.Name
	ProximityPrompt.ObjectText = "Hack"
	ProximityPrompt.HoldDuration = HoldingDuration.Value
	ProximityPrompt.MaxActivationDistance = 70
	ProximityPrompt.RequiresLineOfSight = false
	ProximityPrompt.Style = "Custom"
	ProximityPrompt.Exclusivity = Enum.ProximityPromptExclusivity.AlwaysShow
	ProximityPrompt.Triggered:Connect(function(plr) --Issue starts here.
		print("a")
		if closestPart.Parent.Name == "Lighting" then
			plr.PlayerInformation.Exp.Value = plr.PlayerInformation.Exp.Value + 2
		end
		if closestPart.Parent.Name == "Fire Hydrant" then
			plr.PlayerInformation.Exp.Value = plr.PlayerInformation.Exp.Value + 10
		end
	end)
end

function OnFar()
	Beam.Attachment1 = nil
    ProximityPrompt.Enabled = false
end

local prevClosestPart = nil
RunService.Heartbeat:Connect(function()
	if script.Equipped.Value == true and Debounce == true then
		local closestMagnitude, closestPart = math.huge, nil
		for _, parts in pairs(workspace.Hackable:GetDescendants()) do
			if parts.Name == "BasePart" then
				local distance = (HumanoidRootPart.Position - parts.Position).Magnitude
				if distance < Distance.Value then
					closestPart = parts
					closestMagnitude = distance
				end
			end
		end
		if closestPart then
			if closestPart ~= prevClosestPart then
				OnNear(closestPart) -- It fires the "OnNear" function.
				prevClosestPart = closestPart
			end
		else
			OnFar()
			prevClosestPart = nil
		end
	elseif script.Equipped.Value == false then
		Beam.Attachment1 = nil
		ProximityPrompt.Enabled = false
	end
end)

Try removing one from ProximityPrompt.Enabled = false (Try this one that I have pointed out)