I have a door that slides open when you touch a certain part, and closes automatically after 5 seconds. Problem is, I want it to close only if that part is not being touched. Is there a way to say something like:
if Part.Touched ~= true then
or something similar? (Assume Part is the part that you touch to open the door.) This is my current script:
door = script.Parent.Parent.DoorSlide isOpen = script.Parent.Parent.IsOpen.Value local Debounce = false function MoveOpen() if Debounce then return end if isOpen == false then Debounce = true for i = 1, 80 do door.CFrame = door.CFrame + Vector3.new(-0.05, 0, 0) wait() end isOpen = true Debounce = false end --This is where I think I need to add something else, but I don't know what to add wait(5) if isOpen == true then Debounce = true for i = 1, 80 do door.CFrame = door.CFrame + Vector3.new(0.05, 0, 0) wait() end isOpen = false Debounce = false end end script.Parent.Touched:connect(MoveOpen)
Any help would be appreciated, even if the answer is quite obvious.
There's a neat function of parts called GetTouchingParts
and it returns a table of all parts currently in contact with the part. Just check if the number of parts is zero like so,
local part = script.Parent if #part:GetTouchingParts() > 0 then print("I'm being Touched!") else print("I'm lonely.") end
Good Luck!