Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local spectating = nil
- local spectateIndex = 1
- -- GUI Creation
- local ScreenGui = Instance.new("ScreenGui")
- local Frame = Instance.new("Frame")
- local NextButton = Instance.new("TextButton")
- local PrevButton = Instance.new("TextButton")
- local SpawnButton = Instance.new("TextButton")
- local TitleLabel = Instance.new("TextLabel")
- local SpectateName = Instance.new("TextLabel") -- For displaying the spectated player's name
- -- GUI Setup
- ScreenGui.Parent = game:GetService("CoreGui")
- -- Frame
- Frame.Parent = ScreenGui
- Frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
- Frame.BorderSizePixel = 0
- Frame.Size = UDim2.new(0, 200, 0, 200)
- Frame.Position = UDim2.new(0, 10, 0, 10)
- -- Title Label
- TitleLabel.Parent = Frame
- TitleLabel.Size = UDim2.new(1, 0, 0, 50)
- TitleLabel.BackgroundTransparency = 1
- TitleLabel.Font = Enum.Font.SourceSansBold
- TitleLabel.TextSize = 18
- TitleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
- TitleLabel.Text = "Spectate Menu"
- -- Spectate Name Label
- SpectateName.Parent = ScreenGui
- SpectateName.AnchorPoint = Vector2.new(0.5, 0) -- Centered horizontally
- SpectateName.Position = UDim2.new(0.5, 0, 0, 10)
- SpectateName.Size = UDim2.new(0, 200, 0, 50)
- SpectateName.Font = Enum.Font.SourceSansBold
- SpectateName.TextSize = 24
- SpectateName.TextColor3 = Color3.fromRGB(255, 255, 255)
- SpectateName.TextStrokeTransparency = 0
- SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Default grey for neutral
- SpectateName.BackgroundTransparency = 0.2
- SpectateName.Text = ""
- -- Buttons
- local function setupButton(button, text, position)
- button.Parent = Frame
- button.Size = UDim2.new(0.8, 0, 0, 40)
- button.Position = position
- button.BackgroundColor3 = Color3.fromRGB(100, 100, 200)
- button.Font = Enum.Font.SourceSans
- button.TextSize = 16
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Text = text
- end
- setupButton(NextButton, "Next", UDim2.new(0.1, 0, 0.3, 0))
- setupButton(PrevButton, "Previous", UDim2.new(0.1, 0, 0.5, 0))
- setupButton(SpawnButton, "Spawn", UDim2.new(0.1, 0, 0.7, 0))
- -- Functions
- local function getValidPlayers()
- local allPlayers = Players:GetPlayers()
- local validPlayers = {}
- for _, player in ipairs(allPlayers) do
- if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Humanoid") then
- table.insert(validPlayers, player)
- end
- end
- return validPlayers
- end
- local function updateSpectating()
- local validPlayers = getValidPlayers()
- if #validPlayers == 0 then
- spectating = nil
- Camera.CameraSubject = LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("Humanoid")
- SpectateName.Text = ""
- SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Neutral grey
- return
- end
- if spectateIndex > #validPlayers then
- spectateIndex = 1
- elseif spectateIndex < 1 then
- spectateIndex = #validPlayers
- end
- spectating = validPlayers[spectateIndex]
- if spectating and spectating.Character and spectating.Character:FindFirstChild("Humanoid") then
- Camera.CameraSubject = spectating.Character.Humanoid
- SpectateName.Text = spectating.Name
- -- Update background color based on team
- local team = spectating.Team
- if team then
- SpectateName.BackgroundColor3 = team.TeamColor.Color -- Use team color
- else
- SpectateName.BackgroundColor3 = Color3.fromRGB(128, 128, 128) -- Neutral grey
- end
- end
- end
- local function teleportToSpectated()
- if spectating and spectating.Character and spectating.Character:FindFirstChild("HumanoidRootPart") then
- local targetPosition = spectating.Character.HumanoidRootPart.Position
- if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
- LocalPlayer.Character:SetPrimaryPartCFrame(CFrame.new(targetPosition + Vector3.new(0, 5, 0)))
- Camera.CameraSubject = LocalPlayer.Character:FindFirstChild("Humanoid")
- end
- end
- end
- -- Button Actions
- NextButton.MouseButton1Click:Connect(function()
- spectateIndex = spectateIndex + 1
- updateSpectating()
- end)
- PrevButton.MouseButton1Click:Connect(function()
- spectateIndex = spectateIndex - 1
- updateSpectating()
- end)
- SpawnButton.MouseButton1Click:Connect(function()
- teleportToSpectated()
- end)
- -- Start spectating the first valid player
- updateSpectating()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement