Advertisement
HowToRoblox

LimitDoorHandler

Aug 1st, 2020
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local limitDoorModel = script.Parent
  2.  
  3. local door = limitDoorModel:WaitForChild("Door")
  4.  
  5. local teleportInsidePart = limitDoorModel:WaitForChild("TeleportInside")
  6. local teleportOutsidePart = limitDoorModel:WaitForChild("TeleportOutside")
  7.  
  8. local surfaceGui = door:WaitForChild("PlayerAmountGui")
  9. local textLabel = surfaceGui:WaitForChild("PlayerAmount")
  10.  
  11.  
  12. local plrsInside = {}
  13.  
  14. local plrLimit = 2
  15.  
  16. local cooldownPerPlr = 0.5
  17. local plrsOnCooldown = {}
  18.  
  19.  
  20. door.Touched:Connect(function(touched)
  21.    
  22.     local char = touched.Parent
  23.     local plr = game.Players:GetPlayerFromCharacter(char)
  24.    
  25.     if plrsOnCooldown[plr] then return end
  26.    
  27.     if plr and not plrsInside[plr] then
  28.        
  29.         local amountOfPlrs = textLabel.Text
  30.         if tonumber(amountOfPlrs) >= plrLimit then return end
  31.        
  32.         textLabel.Text = tonumber(textLabel.Text) + 1
  33.        
  34.         plrsInside[plr] = true
  35.        
  36.         char.HumanoidRootPart.CFrame = teleportInsidePart.CFrame
  37.        
  38.         plrsOnCooldown[plr] = true
  39.         wait(cooldownPerPlr)
  40.         plrsOnCooldown[plr] = nil
  41.        
  42.     elseif plr and plrsInside[plr] then
  43.        
  44.         textLabel.Text = tonumber(textLabel.Text) - 1
  45.        
  46.         plrsInside[plr] = nil
  47.        
  48.         char.HumanoidRootPart.CFrame = teleportOutsidePart.CFrame
  49.        
  50.         plrsOnCooldown[plr] = true
  51.         wait(cooldownPerPlr)
  52.         plrsOnCooldown[plr] = nil
  53.     end
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement