Unable to figure out placement of debounce and Dot Product in door script

I’ve been trying to insert a debounce/cooldown into my door script, but so far none have worked. I have also attempted to determine what side of the door the player stands on, so it always opens outward, but I have no idea where to start (tried a solution from the forums, but couldn’t figure out how to continue). A little bit of guidance would be very much appreciated!

I got most of the code from this video: Custom Proximity Prompt Tutorial - YouTube, but without the Beam, and the door swings open instead of moving to the side.

Code (script in ServerScriptService, although I heard that tweening server-side is problematic and looks choppy, especially when I plan on using multiple doors):

local PPS, TS, RS = game:GetService("ProximityPromptService"), game:GetService("TweenService"), game:GetService("ReplicatedStorage")
local DoorEvent = RS:WaitForChild("DoorEvent")

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		local Hinge = Prompt.Parent.Parent.Hinge
		local Door = Prompt.Parent
		local Debounce = false

		local Open = {}
		Open.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
		local Close = {}
		Close.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)

		local DoorTweenInfo = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) --set the time to 5 seconds to see if I can still interact with it during this time
		local OpenTween = TS:Create(Hinge, DoorTweenInfo, Open)
		local CloseTween = TS:Create(Hinge, DoorTweenInfo, Close)
		
		local function isPositionInFront(position)
			return (Door.Position - position).Unit:Dot(Door.CFrame.LookVector) > 0
		end --here I tried to implement the side thing I mentioned

		if Debounce then return end
		Debounce = true
		if Prompt.ActionText == "Open" then
			OpenTween:Play()
			Prompt.ActionText = "Close"
		else
			CloseTween:Play()
			Prompt.ActionText = "Open"
		end
		task.wait(5)
		Debounce = false
	end
end

PPS.PromptTriggered:Connect(PromptTriggered)

Just move your first statement about debounce outside of the function:

local PPS, TS, RS = game:GetService("ProximityPromptService"), game:GetService("TweenService"), game:GetService("ReplicatedStorage")
local DoorEvent = RS:WaitForChild("DoorEvent")
local Debounce = false -- MOVED TO HERE

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		local Hinge = Prompt.Parent.Parent.Hinge
		local Door = Prompt.Parent
		-- local Debounce = false MOVED

		local Open = {}
		Open.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
		local Close = {}
		Close.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)

		local DoorTweenInfo = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) --set the time to 5 seconds to see if I can still interact with it during this time
		local OpenTween = TS:Create(Hinge, DoorTweenInfo, Open)
		local CloseTween = TS:Create(Hinge, DoorTweenInfo, Close)
		
		local function isPositionInFront(position)
			return (Door.Position - position).Unit:Dot(Door.CFrame.LookVector) > 0
		end --here I tried to implement the side thing I mentioned

		if Debounce then return end
		Debounce = true
		if Prompt.ActionText == "Open" then
			OpenTween:Play()
			Prompt.ActionText = "Close"
		else
			CloseTween:Play()
			Prompt.ActionText = "Open"
		end
		task.wait(5)
		Debounce = false
	end
end

PPS.PromptTriggered:Connect(PromptTriggered)
1 Like

You could use two Parts and TouchEvents to figure out which side of the door they are on.

1 Like

Yup, that works! Gonna mark this as the solution since it was my primary goal in this post after all. Though, I do have one more query, and that is that I heard there’s a way to use Remote Events (server to all clients) to tween doors, instead of tweening them on the server (since, as I mentioned, that makes them look choppy and might cause performance issues?)? Or should I make a new topic for this

Remote Events are easy to understand but hard to explain.

Here is some great info:

If your not into reading, here is a video:

1 Like

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