local m=Players.LocalPlayer local U={targetChanged=Signal.new(),actionActivated=Signal.new(),targetInstance=nil;isRunning=false}local function q(m,q,n)if not U.targetInstance then return Enum.ContextActionResult.Pass end if q==Enum.UserInputState.Begin then U.actionActivated:fire(U.targetInstance)end end local function n()local q=m.Character and m.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if not q then return end local n=getNearestTagged(q.Position,"\065\099\116\105\111\110",MAX_CUTTOFF_DISTANCE)if n then if n~=U.targetInstance then U.targetChanged:fire({enabled=true;newTargetInstance=n;oldTargetInstance=U.targetInstance,sizeOffset=ACTION_BUTTON_OFFSET})end else U.targetChanged:fire({enabled=false;newTargetInstance=n;oldTargetInstance=U.targetInstance})end U.targetInstance=n end function U.start()RunService:BindToRenderStep("\071\101\116\065\099\116\105\111\110\084\097\114\103\101\116",Enum.RenderPriority.Camera.Value-1,function()n()end)ContextActionService:BindActionAtPriority("\065\099\116\105\111\110\065\099\116\105\118\097\116\101",q,false,ACTION_PRIORITY,ACTIVATE_KEYBOARD,ACTIVATE_CONSOLE)U.isRunning=true end function U.stop()RunService:UnbindFromRenderStep("\071\101\116\065\099\116\105\111\110\084\097\114\103\101\116")U.isRunning=false end function U.activate()if not U.targetInstance then return end U.actionActivated:fire(U.targetInstance)end
--[[
	Implementation
]]

local localPlayer = Players.LocalPlayer

local ActionPrompts = {
	targetChanged = Signal.new(),
	actionActivated = Signal.new(),
	targetInstance = nil,
	isRunning = false,
}

local function contextActivate(actionName, userInputState, inputObject)
	if not ActionPrompts.targetInstance then
		return Enum.ContextActionResult.Pass
	end

	if userInputState == Enum.UserInputState.Begin then
		ActionPrompts.actionActivated:fire(ActionPrompts.targetInstance)
	end
end

local function getTarget()
	local humanoidRootPart = localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart")

	if not humanoidRootPart then
		return
	end

	local closestAction = getNearestTagged(humanoidRootPart.Position, "Action", MAX_CUTTOFF_DISTANCE)

	if closestAction then
		if closestAction ~= ActionPrompts.targetInstance then
			ActionPrompts.targetChanged:fire({
				enabled = true,
				newTargetInstance = closestAction,
				oldTargetInstance = ActionPrompts.targetInstance,
				sizeOffset = ACTION_BUTTON_OFFSET,
			})
		end
	else
		ActionPrompts.targetChanged:fire({
			enabled = false,
			newTargetInstance = closestAction,
			oldTargetInstance = ActionPrompts.targetInstance,
		})
	end

	ActionPrompts.targetInstance = closestAction
end

function ActionPrompts.start()
	RunService:BindToRenderStep("GetActionTarget", Enum.RenderPriority.Camera.Value - 1, function()
		getTarget()
	end)

	ContextActionService:BindActionAtPriority(
		"ActionActivate",
		contextActivate,
		false,
		ACTION_PRIORITY,
		ACTIVATE_KEYBOARD,
		ACTIVATE_CONSOLE
	)

	ActionPrompts.isRunning = true
end

function ActionPrompts.stop()
	RunService:UnbindFromRenderStep("GetActionTarget")

	ActionPrompts.isRunning = false
end

function ActionPrompts.activate()
	if not ActionPrompts.targetInstance then
		return
	end

	ActionPrompts.actionActivated:fire(ActionPrompts.targetInstance)
end
