Hi! So I made this sliding door in my game and I think it works pretty well, but there is one problem. The door shuts in your face if you stay there for too long. I need it to stay open when a player touched it, and only close when nobody is touching it. I want to know how to check if my detector is not being touched, so it doesn't shut on anyone's face. Is there any piece of script that I could use for this? Preferably something that can be used in a if statement? If not then are there any other ways I could avoid this problem? Help is much appreciated. Thanks!
p.s. If you need the code here it is:
local TweenService = game:GetService("TweenService") local Door1 = script.Parent:WaitForChild("Door1") local Door2 = script.Parent:WaitForChild("Door2") local tweeningInformation = TweenInfo.new( 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0 ) local Door1Open = {CFrame = CFrame.new(29.706, 4.155, -47.327)} local Door2Open = {CFrame = CFrame.new(29.706, 4.155, -30.987)} local Door1Close = {CFrame = CFrame.new(29.706, 4.155, -41.823)} local Door2Close = {CFrame = CFrame.new(29.706, 4.155, -36.487)} local Tween1Open = TweenService:Create(Door1,tweeningInformation,Door1Open) local Tween1Close = TweenService:Create(Door1,tweeningInformation,Door1Close) local Tween2Open = TweenService:Create(Door2,tweeningInformation,Door2Open) local Tween2Close = TweenService:Create(Door2,tweeningInformation,Door2Close) local dooropen = false script.Parent.Detector1.Touched:Connect(function() if dooropen == false then dooropen = true Tween1Open:Play() Tween2Open:Play() wait(2) Tween1Close:Play() Tween2Close:Play() dooropen = false end end) script.Parent.Detector2.Touched:Connect(function(hit) if dooropen == false then dooropen = true Tween1Open:Play() Tween2Open:Play() wait(2) Tween1Close:Play() Tween2Close:Play() dooropen = false end end)
You can use GetTouchingParts()
to get the list of all parts with CanCollide set to true that are touching (intersectign with) the door.
So, if you wanted to make it to a function, it would look like this:
local function IsAnythingTouchingThisPart(part) return #part:GetTouchingParts() ~= 0 end
while part:FindFirstChild("Humanoid") ~= nil do -- Code Here end