Advertisement
fishinthebox

Spectator System (Client)

Apr 28th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. local Holder = script.Parent:WaitForChild("Frame")
  2. local SpectatingText = Holder.Frame.PlayerName
  3. local RestartText = Holder.Restart
  4. local Next = Holder.Next
  5. local Previous = Holder.Previous
  6.  
  7. local BossFrame = script.Parent.Parent:WaitForChild("BossBars")
  8.  
  9. local Players = game:GetService("Players")
  10. local Player = Players.LocalPlayer
  11.  
  12. local Camera = workspace.CurrentCamera
  13.  
  14. local IsDead = false
  15.  
  16. local PlayerList = {}
  17.  
  18. Holder.Visible = false
  19.  
  20. local function GetHumFromPlayer(plr: Player)
  21.     local plrchar = plr.Character or plr.CharacterAdded:Wait()
  22.  
  23.     local h = plrchar:FindFirstChildOfClass('Humanoid') or plrchar:WaitForChild("Humanoid")
  24.    
  25.     return h
  26. end
  27.  
  28. for _, plr in Players:GetPlayers() do
  29.     if plr.Character then
  30.         if plr.Character:FindFirstChildOfClass("Humanoid") then
  31.             table.insert(PlayerList, plr)
  32.         end
  33.     end
  34. end
  35.  
  36. Players.PlayerAdded:Connect(function(plr)
  37.     GetHumFromPlayer(plr)
  38.    
  39.     table.insert(PlayerList, plr)
  40. end)
  41.  
  42. Players.PlayerRemoving:Connect(function(plr)
  43.     table.remove(PlayerList, table.find(PlayerList, plr))
  44. end)
  45.  
  46. local function RestartChar(Char)
  47.     print("YES")
  48.     Holder.Visible = false
  49.     BossFrame.Enabled = true
  50.     Camera.CameraType = Enum.CameraType.Custom
  51.  
  52.     local Hum: Humanoid = Char:FindFirstChildOfClass("Humanoid") or Char:WaitForChild("Humanoid")
  53.  
  54.     Camera.CameraSubject = Hum
  55.     IsDead = false
  56.    
  57.     Hum.Died:Once(function()
  58.         if workspace.Values.GameActive.Value == false then return end
  59.         Holder.Visible = true
  60.         IsDead = true
  61.  
  62.         Camera.CameraType = Enum.CameraType.Watch
  63.        
  64.         SpectatingText.Text = Player.DisplayName
  65.         BossFrame.Enabled = false
  66.        
  67.         for i = 25, 0, -1 do
  68.             task.wait(1)
  69.             RestartText.Text = "You respawn in: " .. i
  70.         end
  71.     end)
  72. end
  73.  
  74. Player.CharacterAdded:Connect(function(Char)
  75.     RestartChar(Char)
  76. end)
  77.  
  78. Next.MouseButton1Click:Connect(function()
  79.     if not IsDead then return end
  80.    
  81.     local Index = table.find(PlayerList, Player)
  82.    
  83.     Index += 1
  84.    
  85.     if Index > #PlayerList then
  86.         Index = 1
  87.     end
  88.    
  89.     local plr = PlayerList[Index]
  90.    
  91.     print(Index, PlayerList)
  92.    
  93.     SpectatingText.Text = plr.DisplayName
  94.     Camera.CameraSubject = GetHumFromPlayer(plr)
  95. end)
  96.  
  97. Previous.MouseButton1Click:Connect(function()
  98.     if not IsDead then return end
  99.  
  100.     local Index = table.find(PlayerList, Player)
  101.    
  102.     Index -= 1
  103.    
  104.     if Index < 1 then
  105.         Index = #PlayerList
  106.     end
  107.  
  108.     local plr = PlayerList[Index]
  109.  
  110.     SpectatingText.Text = plr.DisplayName
  111.     Camera.CameraSubject = GetHumFromPlayer(plr)
  112. end)
  113.  
  114. if Player.Character then
  115.     RestartChar(Player.Character)
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement