Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you have the player hold down LMB on a clickdetector?

Hey! This is another part for my survival game. The player has curtains to shut the bad people out, and I want to prevent them from keeping them closed forever. So, what I'm trying to do is when the player holds down LMB(LeftMouseButton), the curtains close. But when they release their mouse button, the curtains open. I've searched the internet for ways to do this, but I haven't found a single one. Can anyone help me with this?

Any working answer is appreciated, thanks!

1 comment

0

no its a CLICK detector i recomend using function onButton1Down(mouse) see its not that hard :)

1 answer

✓ Accepted answer

You can't make the player hold down the mouse click, BUT you can make a timer script that re-opens your curtains after a set amount of time.

Something like:

local ClickDetector = script.Parent:WaitForChild("ClickDetector",10)
if(ClickDetector == nil) then
	error("Error!: Cannot find a ClickDetector inside this part! \n "..debug.traceback())
else
	print("ClickDetector test Loaded!")
end
ClickDetector.MaxActivationDistance = 20
local CloseCurtains = false
local TimeTillopen =  10.25 -- in seconds!

ClickDetector.MouseClick:Connect(function()
	if(CloseCurtains == false) then
		CloseCurtains = true -- open the curtains tag
		local time = tick() -- reference the current start time after click
		while true do
			local GT = tick() -- get the tick time
			local NT =  GT - time -- Subtract the tick time from the start time
			--print(NT," :: ",TimeTillopen) -- debugging
			if(NT >= TimeTillopen) then -- if this new time is greater than TimeTillopen  then break out of this loop
				break
			end
			wait()
		end
		-- Broken out of loop lets set this value back to false thus opening the curtains
		CloseCurtains = false
	end
end)

-- this loop is to show the output of this script!
while true do
	print("curtains are ",CloseCurtains == true and "Closed" or "Open!")
	wait()
end

Get back to me if you need help and hope this helps! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.