ProximityPrompt Needs to Be Pressed Twice to Trigger First Time

Hello developers, I am struggling with an issue in my game where I need to press a ProximityPrompt twice for it to work the first time. After the first press, it works fine, but at the start, it requires two presses. I’ve been trying to figure out why this is happening and have tried a few things, but the problem still continues. I would really appreciate some help or suggestions to fix this!

  1. What do you want to achieve?

I want to make two parts move smoothly to different locations when the ProximityPrompt is triggered by the player. The parts should move only after the previous movement is finished.

  1. What is the issue?

The problem is that I need to press the ProximityPrompt twice to make it work at the start of the game. After that, it works fine, but at first, I need to press it twice for it to trigger. I’m not sure why this is happening.

  1. What solutions have you tried so far?
  • I tried adding a check to make sure the tween isn’t already running before the ProximityPrompt triggers again.

  • I also tried waiting for the tween to finish before allowing the next one, but the issue still happens.

  • I read some stuff on the Developer Hub about tweens and ProximityPrompts, but couldn’t find anything that talks about needing to press the prompt twice at the start.

HERE’S THE SCRIPT =

local metalTarget = script.Parent:WaitForChild("MetalTarget")
local unionPart = metalTarget:WaitForChild("Union")  -- The union part that moves
local transparentPart = metalTarget:WaitForChild("Part")  -- The transparent part with the decal

local tweenService = game:GetService("TweenService")

-- Tween Information
local tweenInfo = TweenInfo.new(
	3, -- Duration (time in seconds for each move)
	Enum.EasingStyle.Linear, -- Easing style for smoothness
	Enum.EasingDirection.Out, -- Direction of the easing (slower at the start)
	0, -- Repeat count (no repeat)
	false, -- Reverse the tween (no)
	0 -- Delay time (no delay)
)

-- Function to move both parts to a specific location smoothly
local function moveToLocation(location)
	-- Get the target position
	local targetPosition = location.Position

	-- Tween for union part (keeping Y constant)
	local unionTweenGoal = { Position = Vector3.new(targetPosition.X, unionPart.Position.Y, targetPosition.Z) }
	local unionTween = tweenService:Create(unionPart, tweenInfo, unionTweenGoal)
	unionTween:Play()

	-- Tween for transparent part (keeping Y constant)
	local transparentTweenGoal = { Position = Vector3.new(targetPosition.X, transparentPart.Position.Y, targetPosition.Z) }
	local transparentTween = tweenService:Create(transparentPart, tweenInfo, transparentTweenGoal)
	transparentTween:Play()
end

-- Get the ProximityPrompt
local button = script.Parent:WaitForChild("Button")
local proximityPrompt = button:WaitForChild("TargetPrompt")

-- Locations for the movement
local locations = script.Parent:WaitForChild("Locations"):GetChildren()

-- Ensure locations are sorted by their name
table.sort(locations, function(a, b)
	return a.Name < b.Name
end)

-- Variable to track the current location index
local currentLocationIndex = 1

-- Function to handle ProximityPrompt trigger
local function onPromptTriggered()
	-- Get the current location (based on the index)
	local currentLocation = locations[currentLocationIndex]

	-- Move to the current location
	moveToLocation(currentLocation)

	-- Update the proximity prompt text dynamically
	if currentLocationIndex == 4 then
		proximityPrompt.ActionText = "Return Target"
	else
		proximityPrompt.ActionText = "Bring Target Closer"
	end

	-- Increment location index and cycle back to 1 if at the last location
	currentLocationIndex = currentLocationIndex % #locations + 1
end

-- Connect ProximityPrompt trigger to the function
proximityPrompt.Triggered:Connect(onPromptTriggered)

Model:
(rbxm file of my model was here)

Thank you!!

This sounds dumb but is location 1 where it starts at? Or is it a different location?
If so, initialize currentLocationIndex to 2 instead of 1

1 Like

That worked, thanks so much. Why am I so stupid? Lol

Alternatively, you can increment first instead of last in your function.