Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if a part is not being touched by anyone?

Asked by
Faazo 84
6 years ago

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)

0
the thing you want to do is like make a script that will do so that the door never closes until the player is a bit away? policopi 37 — 6y

2 answers

Log in to vote
3
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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
0
Nevermind, I understand it now. Thank you! Faazo 84 — 5y
Ad
Log in to vote
-2
Answered by 6 years ago
while part:FindFirstChild("Humanoid") ~= nil do
    -- Code Here
end

Answer this question