Advertisement
LightningTNT

Spectate GUI script

Nov 21st, 2020
2,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1.  
  2. local Players = game:GetService("Players")
  3. local plr = Players.LocalPlayer
  4. local camera = workspace.CurrentCamera
  5. local index = 1
  6.  
  7. function setIndex(change)
  8.     local list = Players:GetPlayers()
  9.     if((index+change) < 1) then
  10.         index = #list
  11.     elseif((index+change) > #list) then
  12.         index = 1
  13.     else
  14.         index = index+change
  15.     end
  16.    
  17.     local target = list[index]
  18.     local char = target.Character or target.CharacterAdded:Wait()
  19.     local hum = char:WaitForChild("Humanoid")
  20.     camera.CameraSubject = char
  21.     script.Parent.PlayerName.Text = target.Name
  22. end
  23.  
  24. script.Parent.Parent.Spectate.InputBegan:Connect(function(input)
  25.     if(input.UserInputType == Enum.UserInputType.MouseButton1) then
  26.         local char = plr.Character or plr.CharacterAdded:Wait()
  27.         local hum = char:WaitForChild("Humanoid")
  28.         if(script.Parent.Position ~= UDim2.new(0.338, 0,0.792,0)) then
  29.             script.Parent:TweenPosition(UDim2.new(0.338, 0,0.792,0))
  30.             script.Parent.PlayerName.Text = plr.Name
  31.             hum.WalkSpeed = 0 --Disable player movement
  32.         else
  33.             script.Parent:TweenPosition(UDim2.new(0.338, 0, 1.2, 0))
  34.             camera.CameraSubject = hum
  35.             hum.WalkSpeed = 16
  36.         end
  37.     end
  38. end)
  39.  
  40. script.Parent.Forward.InputBegan:Connect(function(input)
  41.     if(input.UserInputType == Enum.UserInputType.MouseButton1) then
  42.         setIndex(1)
  43.     end
  44. end)
  45.  
  46. script.Parent.Backward.InputBegan:Connect(function(input)
  47.     if(input.UserInputType == Enum.UserInputType.MouseButton1) then
  48.         setIndex(-1)
  49.     end
  50. end)
  51. --I am honestly not sure whether to use InputBegan or Activated, I just used InputBegan for now.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement