How to detect if a player is holding left click on a brick

i want it so when the player holds left click on the button of my door it closes it but when they let go it opens it. my door script:

local LargeDoor = game.Workspace:FindFirstChild("LargeDoor")
local toggle = true
LargeDoor.PrimaryPart = LargeDoor:WaitForChild("Center")
script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function()
	if toggle == false then
		LargeDoor:SetPrimaryPartCFrame(CFrame.new(-497.15, 11.35, -7.5)) 
		toggle = true
	elseif toggle == true then
		LargeDoor:SetPrimaryPartCFrame(CFrame.new(-497.15, 11.35, -7.5)) 
		toggle = false
	end
end)

i cant think of any ways to do this? thank you

You probably should use a Proximity Prompts | Roblox Creator Documentation which have ProximityPromptService | Roblox Creator Documentation, ProximityPromptService | Roblox Creator Documentation, and ProximityPromptService | Roblox Creator Documentation events.
In the first link they have a sample script using the last 3 linked items.

As @Scottifly already said, using ProximityPrompt Service will be the best solution.
However, it looks like you are using a ClickDetector and you can’t use a hold mouse button for it. Just. (At least I think so.)

So well, ProximityPrompt is the only way as of now.

how do i edit the properties to make it holding for an infinite amount of time since i want the door to be closed while there holding it and to lift up when they let go

That’s why there’s the PromptButtonHoldBegan and PromptButtonHoldEnded events…

Also, you can’t hold the button for an infinite amount of time because that’s forever. You hold it for a finite amount of time.

1 Like