Advertisement
HowToRoblox

AutomaticDoorHandler

Feb 29th, 2020
2,608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local lDoor = script.Parent.LeftDoor
  2. local rDoor = script.Parent.RightDoor
  3.  
  4. local lDoorClosed = script.Parent.LeftDoorClosedPos
  5. local lDoorOpened = script.Parent.LeftDoorOpenedPos
  6.  
  7. local rDoorClosed = script.Parent.RightDoorClosedPos
  8. local rDoorOpened = script.Parent.RightDoorOpenedPos
  9.  
  10.  
  11. local sensor = script.Parent.Sensor
  12.  
  13.  
  14. local isOpen = false
  15.  
  16.  
  17. local tweenService = game:GetService("TweenService")
  18. local tweenInfo = TweenInfo.new(1.4, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  19.  
  20. local lTweenOpen = tweenService:Create(lDoor, tweenInfo, {CFrame = lDoorOpened.CFrame})
  21. local lTweenClose = tweenService:Create(lDoor, tweenInfo, {CFrame = lDoorClosed.CFrame})
  22.  
  23. local rTweenOpen = tweenService:Create(rDoor, tweenInfo, {CFrame = rDoorOpened.CFrame})
  24. local rTweenClose = tweenService:Create(rDoor, tweenInfo, {CFrame = rDoorClosed.CFrame})
  25.  
  26.  
  27. while wait() do
  28.    
  29.     local plrs = game.Players:GetPlayers()
  30.    
  31.     for i, plr in pairs(plrs) do
  32.        
  33.         local char = plr.Character or plr.CharacterAdded:Wait()
  34.         local hrp = char:FindFirstChild("HumanoidRootPart")
  35.        
  36.         if not hrp then return end
  37.        
  38.        
  39.         local magnitude = (hrp.Position - sensor.Position).Magnitude
  40.        
  41.        
  42.         if magnitude < 16 then
  43.            
  44.             if isOpen then return end
  45.            
  46.             isOpen = true
  47.            
  48.            
  49.             lTweenOpen:Play()
  50.             rTweenOpen:Play()
  51.            
  52.            
  53.             wait(3)
  54.            
  55.            
  56.             lTweenClose:Play()
  57.             rTweenClose:Play()
  58.            
  59.            
  60.             isOpen = false
  61.            
  62.         end
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement