Advertisement
HowToRoblox

SecurityCameraHandler

Jan 31st, 2020
7,151
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2.  
  3. local char = plr.Character or plr.CharacterAdded:Wait()
  4.  
  5.  
  6. local cam = workspace.CurrentCamera
  7.  
  8.  
  9. local function alphabeticalOrder(instance)
  10.    
  11.     local children = instance:GetChildren()
  12.    
  13.     table.sort(children, function(c1, c2)
  14.        
  15.         return c1.Name:lower() < c2.Name:lower()
  16.        
  17.     end)
  18.    
  19.     return children
  20.    
  21. end
  22.  
  23. local camParts = alphabeticalOrder(workspace.Cameras)
  24.  
  25.  
  26. local LArrow = script.Parent.LeftArrow
  27.  
  28. local RArrow = script.Parent.RightArrow
  29.  
  30.  
  31. local arrowClickCooldown = false
  32.  
  33.  
  34. char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
  35.    
  36.     if not isSeated or seat.Name ~= "CameraSeat" then
  37.        
  38.         script.Parent.LeftArrow.Visible = false
  39.         script.Parent.RightArrow.Visible = false
  40.        
  41.         cam.CameraType = Enum.CameraType.Custom
  42.        
  43.         return
  44.     end
  45.    
  46.    
  47.     script.Parent.LeftArrow.Visible = true
  48.     script.Parent.RightArrow.Visible = true
  49.    
  50.    
  51.     cam.CameraType = Enum.CameraType.Scriptable
  52.    
  53.     cam.CFrame = camParts[1].CFrame
  54.    
  55.    
  56.     local camNumber = 1
  57.    
  58.    
  59.     RArrow.MouseButton1Click:Connect(function()
  60.        
  61.         if arrowClickCooldown then return end
  62.        
  63.         arrowClickCooldown = true
  64.        
  65.        
  66.         if camNumber == #camParts then
  67.            
  68.             cam.CFrame = camParts[1].CFrame
  69.              
  70.             camNumber = 1
  71.         else
  72.            
  73.             cam.CFrame = camParts[camNumber + 1].CFrame
  74.            
  75.             camNumber = camNumber + 1
  76.         end
  77.        
  78.        
  79.         wait(0.1)
  80.        
  81.         arrowClickCooldown = false
  82.        
  83.     end)
  84.    
  85.    
  86.     LArrow.MouseButton1Click:Connect(function()
  87.        
  88.         if arrowClickCooldown then return end
  89.        
  90.         arrowClickCooldown = true
  91.        
  92.        
  93.         if camNumber == 1 then
  94.            
  95.             cam.CFrame = camParts[#camParts].CFrame
  96.            
  97.             camNumber = #camParts
  98.         else
  99.            
  100.             cam.CFrame = camParts[camNumber - 1].CFrame
  101.            
  102.             camNumber = camNumber - 1
  103.         end
  104.        
  105.        
  106.         wait(0.1)
  107.        
  108.         arrowClickCooldown = false
  109.        
  110.     end)
  111.    
  112. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement