Detect if player stopped holding the proximity prompt (without triggering it)

How can i detect if player stopped holding the prompt, without triggering the proximity prompt?

the prompt hold duration is 9 seconds

the script:

local ProximityPrompt = script.Parent
local StartingSound = script.Parent.Parent.Parent.Part.Starting

ProximityPrompt.PromptButtonHoldBegan:Connect(function()
	StartingSound:Play()
	print("Player is starting the machine")
end)

ProximityPrompt.PromptButtonHoldEnded:Connect(function()
	if ProximityPrompt.Triggered then
		StartingSound:Resume()
		print("Player successfully started the machine")
	else
		StartingSound:Stop()
		print("Player failed to start the machine")
	end
end)

current bug:

ProximityPrompt.Triggered is an event, so I don’t think it quites work in the if statement.
May be a better solution to what I have provided below, but it should still work:

local ProximityPrompt = script.Parent
local StartingSound = script.Parent.Parent.Parent.Part.Starting

ProximityPrompt.PromptButtonHoldBegan:Connect(function()
	StartingSound:Play()
    local Triggered = false
	print("Player is starting the machine")
    local conn1 = ProximityPrompt.PromptButtonHoldEnded:Once(function()
        task.wait()
        if Triggered then
            StartingSound:Resume()
		    print("Player successfully started the machine")
        else
            StartingSound:Stop()
		    print("Player failed to start the machine")
            conn2:Disconnect()
        end    
    end)
    local conn2 = ProximityPrompt.Triggered:Once(function()
        Triggered = true
    end)
end)

untested, but logic seems to be correct

1 Like

what are conn1 and conn2? It have yellow lines for me

Forgot to put local in front of them. Conn1 and Conn2 are the variables I assigned the event connections to. The yellow line can be ignored or can be silenced by putting local in front of them. i.e.

local conn1 = ...
local conn2 = ...
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.