Proximity HoldEnded runs before TriggerEnded

How would I fix HoldEnded running before Trigger Ended? (because for my game when you let go of e mid promp it destroys something, so when i actually finish the prompt it still destroys it because holdended goes first for some reason

local isPossibleBreak = true

proximityPromt.TriggerEnded:Connect(function()
	if proximityPromt then proximityPromt:Destroy() end
	debounce = true
	isPossibleBreak = false
	print(isPossibleBreak)
end)

proximityPromt.PromptButtonHoldEnded:Connect(function()
	if debounce then
		debounce = false
		
		if isPossibleBreak then
			moduleScript.BuildModel(modelToBuild.Name, true)
			print(isPossibleBreak)
		else
			if proximityPromt then proximityPromt:Destroy() end
			debounce = true
		end
	end
end)

image

(example gif of breaking mid hold - which works, and when you finish it it still breaks)

Im guessing its because HoldEnded will run both if you finish the ProximityPrompt and let go of the button before it finishes. So i would maybe recommend only using Triggerended

I need the HoldEnded for breaking the building (i’ve added the gif link on the post) and the triggerended

Try using the Triggered event instead of TriggerEnded.

One way to fix this issue is to use a local variable to keep track of whether the TriggerEnded event has been fired. You can set this variable to true when the TriggerEnded event is fired, and then check the value of this variable in the PromptButtonHoldEnded event handler.

If the value is true , then you know that the TriggerEnded event has already been fired and you can skip the code that destroys the proximity prompt.

Here’s an example of how you could implement this:

local isTriggerEnded = false

proximityPromt.TriggerEnded:Connect(function()
  isTriggerEnded = true
  if proximityPromt then proximityPromt:Destroy() end
  debounce = true
  isPossibleBreak = false
  print(isPossibleBreak)
end)

proximityPromt.PromptButtonHoldEnded:Connect(function()
  if debounce then
    debounce = false

    if isPossibleBreak then
      if isTriggerEnded then
        -- Skip the code that destroys the proximity prompt
      else
        if proximityPromt then proximityPromt:Destroy() end
        debounce = true
      end
      moduleScript.BuildModel(modelToBuild.Name, true)
      print(isPossibleBreak)
    else
      if proximityPromt then proximityPromt:Destroy() end
      debounce = true
    end
  end
end)

That’s what the isPossibleBreak is for, and it doesn’t work

same issue still, i think HoldEnded goes off secondly, if i can’t find any solutions ill submit an engine bug

1 Like