Weird ProximityPrompt glitch

So I’ve made some simple open-close doors with proximity prompt. It works that way that:

  1. You trigger prompt
  2. Door opens (prompt gets disabled)
  3. After 5 seconds the door closes and it re-enables the prompt

Well my script for some reason does that when I open the door the prompt gets disabled but only for like a second and then it instantly re-enables the prompt without waiting for doors to fully close (I have 2 seperate prompts on each side of door )

local l = script.Parent.FreezerDoorL.Door
local r = script.Parent.FreezerDoorR.Door
local prompt = script.Parent.Prompt.ProximityPrompt
local prompt2 = script.Parent.Prompt2.ProximityPrompt

local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)
local ti2 = TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In)

local function openDoors()
	-- OPEN DOORS
	prompt.Enabled = false
	prompt2.Enabled = false
	
	prompt2.Parent.ParticleEmitter:Emit(70)
	prompt.Parent.SFX:Play()
	ts:Create(l, ti, {CFrame = CFrame.new(-3.35, 11.35, 13.2) * CFrame.Angles(0, math.rad(90), 0)}):Play()
	ts:Create(r, ti, {CFrame = CFrame.new(-15.65, 11.35, 13.2) * CFrame.Angles(0, math.rad(-90), 0)}):Play()

	-- CLOSE DOORS

	task.wait(5)
	prompt.Parent.SFX:Play()
	ts:Create(l, ti2, {CFrame = CFrame.new(-7.3, 11.35, 13.2) * CFrame.Angles(0, math.rad(90), 0)}):Play()
	ts:Create(r, ti2, {CFrame = CFrame.new(-11.7, 11.35, 13.2) * CFrame.Angles(0, math.rad(-90), 0)}):Play()
	prompt.Enabled = true
	prompt2.Enabled = true
end

prompt.Triggered:Connect(openDoors)
prompt2.Triggered:Connect(openDoors)
1 Like

it’s hard to tell, is this a local or server script?..

2 Likes

server script but I’ve already found a “solution” by instead of disabling the prompt you just set activation distance to 0 still don’t understand why this glitch happens though

Could it be when the player releases the prompt? Some prompt settings disable and enable based off if anyone is selecting it.

Hey there!

I took a look at your code and identified what was causing the glitch, along with a few other edge-case issues that could mess with your doors,
-No Debounce

Here is the updated code you can drop right into your script:

--!strict
local ts: TweenService = game:GetService("TweenService")

type DoorPart = BasePart
type PromptPart = BasePart & {
	ProximityPrompt: ProximityPrompt,
	SFX: Sound,
	ParticleEmitter: ParticleEmitter
}

local parentFolder = script.Parent :: Instance

local l = parentFolder:WaitForChild("FreezerDoorL"):WaitForChild("Door") :: DoorPart
local r = parentFolder:WaitForChild("FreezerDoorR"):WaitForChild("Door") :: DoorPart

local promptHolder1 = parentFolder:WaitForChild("Prompt") :: PromptPart
local promptHolder2 = parentFolder:WaitForChild("Prompt2") :: PromptPart

local prompt: ProximityPrompt = promptHolder1.ProximityPrompt
local prompt2: ProximityPrompt = promptHolder2.ProximityPrompt

local ti: TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)
local ti2: TweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In)

local isBusy: boolean = false --debounce

local function playCFrameTween<T>(instance: T, tweenInfo: TweenInfo, targetCFrame: CFrame): Tween
	local targetPart = instance :: BasePart
	local tween = ts:Create(targetPart, tweenInfo, { CFrame = targetCFrame })
	tween:Play()
	return tween
end

local function setPromptsEnabled<T>(state: boolean, ...: T)
	local promptList = { ... }
	for _, item in ipairs(promptList) do
		local currentPrompt = item :: ProximityPrompt
		currentPrompt.Enabled = state
	end
end

local function openDoors(player: Player): ()
	if isBusy then return end
	isBusy = true

	setPromptsEnabled(false, prompt, prompt2)

	promptHolder2.ParticleEmitter:Emit(70)
	promptHolder1.SFX:Play()

	local openCFrameL: CFrame = CFrame.new(-3.35, 11.35, 13.2) * CFrame.Angles(0, math.rad(90), 0)
	local openCFrameR: CFrame = CFrame.new(-15.65, 11.35, 13.2) * CFrame.Angles(0, math.rad(-90), 0)

	playCFrameTween(l, ti, openCFrameL)
	playCFrameTween(r, ti, openCFrameR)

	task.wait(5)

	promptHolder1.SFX:Play()

	local closeCFrameL: CFrame = CFrame.new(-7.3, 11.35, 13.2) * CFrame.Angles(0, math.rad(90), 0)
	local closeCFrameR: CFrame = CFrame.new(-11.7, 11.35, 13.2) * CFrame.Angles(0, math.rad(-90), 0)

	local closeTweenL = playCFrameTween(l, ti2, closeCFrameL)
	playCFrameTween(r, ti2, closeCFrameR)

	closeTweenL.Completed:Wait()

	setPromptsEnabled(true, prompt, prompt2)
	isBusy = false
end

prompt.Triggered:Connect(openDoors)
prompt2.Triggered:Connect(openDoors)

I hope it’s exactly what you wanted!