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.
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)
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)
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
Also, for the wait, just put “wait(2.5)” before the “while” loop on the 1st script.
Sorry for bumping, but I’d like to share an idea that I use myself.
You could use a SurfaceGui button instead of the ClickDetector, and have a LocalScript change the cursor to a ClickDetector icon (rbxasset://textures\DragCursor.png) when the player moves his mouse over it.