How to detect if a clickdetector click is being held

How could I detect a button click on a 3d object in the workspace with a ClickDetector inside being held for more than 2.5 seconds, which would in my case fire an event?

I’ve seen tutorials with UserInputService, but not ClickDetectors.

The solution doesn’t need to be server-sided, but is very preferred.

1 Like

use proximity prompt :person_shrugging: or use mousebutton1down and mousebutton1up events , personally i’d pick proximity prompt

This isn’t possible, sorry. You could use a SurfaceGui with a button? In which case,

local button = -- button location, example workspace.Part.SurfaceGui.TextButton (might need a frame before textbutton)
local held = false
button.MouseButton1Down:Connect(function()
held = true
while held == true do
-- stuff goes here
end

end)

button.MouseButton1Up:Connect(function()
held = false
end)
1 Like

yeah that"s what i’ve mentioned.

yeah they wanted clickdetectors which only has :MouseClick event not mb1 up or mb1 down, kinda weird they don’t have that.

1 Like

Well, theres a tricky way of making this using Mouse.Button1Up/Button1Down and ClickDetector.MouseClick, if you want.

2 Likes

oh yeah, i’ll write something for this now

It is possible with a localscript, but this doesn’t seem to be working right. I’ll update it in a moment.

local clickdetector = workspace.Part.ClickDetector
local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	held = true
end)

mouse.Button1Up:Connect(function() -- edited because of error was down not up
	held = false
end)

clickdetector.MouseClick:Connect(function()
	while held == true do
		-- held code.
		wait() -- edited so it doesn't crash
	end
end)


new one, two scripts

local clickdetector = workspace.Part.ClickDetector
held = script.Parent:WaitForChild("held")
clickdetector.MouseClick:Connect(function()
	repeat
		wait()
	until held.Value == true
	while held.Value == true do
		-- held code.
		wait() -- edited so it doesn't crash
	end
end)

next:

local clickdetector = workspace.Part.ClickDetector
local mouse = game.Players.LocalPlayer:GetMouse()
heldval = Instance.new("BoolValue")
heldval.Parent = script.Parent
heldval.Name = "held"
held = heldval.Value

mouse.Button1Down:Connect(function()
	held = true
end)

mouse.Button1Up:Connect(function() -- edited because of error was down not up
	held = false
end)

For some reason it won’t work the first time, but will work after :person_shrugging:
Also, for the wait, just put “wait(2.5)” before the “while” loop on the 1st script.