DrawingJhon

Spectator Mode

Nov 13th, 2020 (edited)
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. local plr = game:GetService("Players").LocalPlayer
  2. local mouse = plr:GetMouse()
  3. local Render = game:GetService("RunService").RenderStepped
  4. local Controller = require(plr:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
  5. local cam = workspace.CurrentCamera
  6. local lastZoom = plr.CameraMaxZoomDistance
  7. local lastCamCFrame = cam.CFrame
  8. local CameraPart = Instance.new("Part")
  9. CameraPart.CanCollide = false
  10. CameraPart.Transparency = 1
  11. CameraPart.CFrame = lastCamCFrame
  12. CameraPart.Parent = workspace
  13. local bp = Instance.new("BodyPosition", CameraPart)
  14. bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  15. bp.Position = CameraPart.Position
  16. bp.D = 700
  17. local Enabled = false
  18.  
  19. local function Start()
  20.     Enabled = true
  21.     Controller:Disable()
  22.     plr.CameraMaxZoomDistance = 0
  23.     plr.CameraMinZoomDistance = 0
  24.     bp.Position = cam.CFrame.p
  25.     cam.CameraSubject = CameraPart
  26.     local pressing = {}
  27.     local vel = 1
  28.     local function SetMovement(key, pos)
  29.         pressing[key] = true
  30.         repeat
  31.             bp.Position = bp.Position + ((cam.CFrame * pos).p - cam.CFrame.p)
  32.             Render:Wait()
  33.         until not pressing[key] or not Enabled
  34.     end
  35.     local KDConn, KUConn
  36.     KDConn = mouse.KeyDown:Connect(function(key)
  37.         if not Enabled then KDConn:Disconnect() return end
  38.         local key = key:lower()
  39.         if key == "w" then
  40.             SetMovement("w", CFrame.new(0, 0, -vel))
  41.         elseif key == "d" then
  42.             SetMovement("d", CFrame.new(vel, 0, 0))
  43.         elseif key == "s" then
  44.             SetMovement("s", CFrame.new(0, 0, vel))
  45.         elseif key == "a" then
  46.             SetMovement("a", CFrame.new(-vel, 0, 0))
  47.         elseif key == "e" then
  48.             SetMovement("e", CFrame.new(0, vel, 0))
  49.         elseif key == "q" then
  50.             SetMovement("q", CFrame.new(0, -vel, 0))
  51.         end
  52.     end)
  53.     KUConn = mouse.KeyUp:Connect(function(key)
  54.         if not Enabled then KUConn:Disconnect() return end
  55.         local key = key:lower()
  56.         pressing[key] = false
  57.     end)
  58. end
  59. local function End()
  60.     Enabled = false
  61.     Controller:Enable()
  62.     cam.CameraSubject = plr.Character and plr.Character:findFirstChildOfClass("Humanoid")
  63.     plr.CameraMaxZoomDistance = lastZoom
  64.     wait()
  65.     cam.CFrame = lastCamCFrame
  66. end
  67.  
  68. mouse.KeyDown:Connect(function(k)
  69.     if k:lower() == "c" then
  70.         if Enabled then
  71.             End()
  72.         else
  73.             Start()
  74.         end
  75.     end
  76. end)
Add Comment
Please, Sign In to add comment