Advertisement
HowToRoblox

PressurePlateHandler

Mar 13th, 2021
2,587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local plate = script.Parent:WaitForChild("Plate")
  2. local door = script.Parent:WaitForChild("Door")
  3. local region = script.Parent:WaitForChild("PlateRegion")
  4.  
  5. local ts = game:GetService("TweenService")
  6. local ti = TweenInfo.new(0.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
  7.  
  8. local plateDownTween = ts:Create(plate, ti, {Position = plate.Position - Vector3.new(0, plate.Size.Y/2, 0)})
  9. local plateUpTween = ts:Create(plate, ti, {Position = plate.Position})
  10.  
  11. local touching = {}
  12.  
  13.  
  14.  
  15. region.Touched:Connect(function(hit)
  16.    
  17.    
  18.     if hit.Name == "HumanoidRootPart" and #touching < 1 then
  19.        
  20.         table.insert(touching, hit)
  21.        
  22.        
  23.         plateDownTween:Play()
  24.         door.Transparency = 1
  25.         door.CanCollide = false
  26.     end
  27. end)
  28.  
  29.  
  30. region.TouchEnded:Connect(function(hit)
  31.    
  32.    
  33.     if hit.Name == "HumanoidRootPart" then
  34.  
  35.         table.remove(touching, touching[hit])
  36.     end
  37.    
  38.    
  39.     if #touching < 1 then
  40.        
  41.         plateUpTween:Play()
  42.         door.Transparency = 0
  43.         door.CanCollide = true
  44.     end
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement