Advertisement
AnonymousJG179

Spectating Spawner

Jan 2nd, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. -- Variables
  2. local Players = game:GetService("Players")
  3. local LocalPlayer = Players.LocalPlayer
  4. local Camera = workspace.CurrentCamera
  5. local spectating = nil
  6. local spectateIndex = 1
  7.  
  8. -- GUI Creation
  9. local ScreenGui = Instance.new("ScreenGui")
  10. local Frame = Instance.new("Frame")
  11. local NextButton = Instance.new("TextButton")
  12. local PrevButton = Instance.new("TextButton")
  13. local SpawnButton = Instance.new("TextButton")
  14. local TitleLabel = Instance.new("TextLabel")
  15. local SpectateName = Instance.new("TextLabel") -- For displaying the spectated player's name
  16.  
  17. -- GUI Setup
  18. ScreenGui.Parent = game:GetService("CoreGui")
  19.  
  20. -- Frame
  21. Frame.Parent = ScreenGui
  22. Frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
  23. Frame.BorderSizePixel = 0
  24. Frame.Size = UDim2.new(0, 200, 0, 200)
  25. Frame.Position = UDim2.new(0, 10, 0, 10)
  26.  
  27. -- Title Label
  28. TitleLabel.Parent = Frame
  29. TitleLabel.Size = UDim2.new(1, 0, 0, 50)
  30. TitleLabel.BackgroundTransparency = 1
  31. TitleLabel.Font = Enum.Font.SourceSansBold
  32. TitleLabel.TextSize = 18
  33. TitleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  34. TitleLabel.Text = "Spectate Menu"
  35.  
  36. -- Spectate Name Label
  37. SpectateName.Parent = ScreenGui
  38. SpectateName.AnchorPoint = Vector2.new(0.5, 0) -- Centered horizontally
  39. SpectateName.Position = UDim2.new(0.5, 0, 0, 10)
  40. SpectateName.Size = UDim2.new(0, 200, 0, 50)
  41. SpectateName.Font = Enum.Font.SourceSansBold
  42. SpectateName.TextSize = 24
  43. SpectateName.TextColor3 = Color3.fromRGB(255, 255, 255)
  44. SpectateName.TextStrokeTransparency = 0
  45. SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Default grey for neutral
  46. SpectateName.BackgroundTransparency = 0.2
  47. SpectateName.Text = ""
  48.  
  49. -- Buttons
  50. local function setupButton(button, text, position)
  51. button.Parent = Frame
  52. button.Size = UDim2.new(0.8, 0, 0, 40)
  53. button.Position = position
  54. button.BackgroundColor3 = Color3.fromRGB(100, 100, 200)
  55. button.Font = Enum.Font.SourceSans
  56. button.TextSize = 16
  57. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  58. button.Text = text
  59. end
  60.  
  61. setupButton(NextButton, "Next", UDim2.new(0.1, 0, 0.3, 0))
  62. setupButton(PrevButton, "Previous", UDim2.new(0.1, 0, 0.5, 0))
  63. setupButton(SpawnButton, "Spawn", UDim2.new(0.1, 0, 0.7, 0))
  64.  
  65. -- Functions
  66. local function getValidPlayers()
  67. local allPlayers = Players:GetPlayers()
  68. local validPlayers = {}
  69.  
  70. for _, player in ipairs(allPlayers) do
  71. if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Humanoid") then
  72. table.insert(validPlayers, player)
  73. end
  74. end
  75.  
  76. return validPlayers
  77. end
  78.  
  79. local function updateSpectating()
  80. local validPlayers = getValidPlayers()
  81.  
  82. if #validPlayers == 0 then
  83. spectating = nil
  84. Camera.CameraSubject = LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("Humanoid")
  85. SpectateName.Text = ""
  86. SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Neutral grey
  87. return
  88. end
  89.  
  90. if spectateIndex > #validPlayers then
  91. spectateIndex = 1
  92. elseif spectateIndex < 1 then
  93. spectateIndex = #validPlayers
  94. end
  95.  
  96. spectating = validPlayers[spectateIndex]
  97.  
  98. if spectating and spectating.Character and spectating.Character:FindFirstChild("Humanoid") then
  99. Camera.CameraSubject = spectating.Character.Humanoid
  100. SpectateName.Text = spectating.Name
  101.  
  102. -- Update background color based on team
  103. local team = spectating.Team
  104. if team then
  105. SpectateName.BackgroundColor3 = team.TeamColor.Color -- Use team color
  106. else
  107. SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Neutral grey
  108. end
  109. end
  110. end
  111.  
  112. local function teleportToSpectated()
  113. if spectating and spectating.Character and spectating.Character:FindFirstChild("HumanoidRootPart") then
  114. local targetPosition = spectating.Character.HumanoidRootPart.Position
  115. if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
  116. LocalPlayer.Character:SetPrimaryPartCFrame(CFrame.new(targetPosition + Vector3.new(0, 5, 0)))
  117. Camera.CameraSubject = LocalPlayer.Character:FindFirstChild("Humanoid")
  118. end
  119. end
  120. end
  121.  
  122. -- Button Actions
  123. NextButton.MouseButton1Click:Connect(function()
  124. spectateIndex = spectateIndex + 1
  125. updateSpectating()
  126. end)
  127.  
  128. PrevButton.MouseButton1Click:Connect(function()
  129. spectateIndex = spectateIndex - 1
  130. updateSpectating()
  131. end)
  132.  
  133. SpawnButton.MouseButton1Click:Connect(function()
  134. teleportToSpectated()
  135. end)
  136.  
  137. -- Start spectating the first valid player
  138. updateSpectating()
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement