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!
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! :)