I made a SpectatorUI today and it works great! but there is a problem…
When I click on the UI it spectates another player but when I close the spectate button the camera is just stuck on the player I was spectating.
Is there a way to make it so that while I’m spectating another player and I close the spectate button the camera switches back to my character?
Here’s the script:
local toggle = script.Parent.Toggle
local frame = script.Parent.SpecFrame
local previous = frame.Prev
local next = frame.Next
local status = frame.StatusRound.Status
local camera = game.Workspace.CurrentCamera
local num = 1
status.Text = game.Players.LocalPlayer.Name
toggle.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
previous.MouseButton1Click:Connect(function()
local players = game.Players:GetChildren()
local max = #players
num = num - 1
if num < 1 then
num = max
end
local player = players[num]
camera.CameraSubject = player.Character.Humanoid
status.Text = player.Name
end)
next.MouseButton1Click:Connect(function()
local players = game.Players:GetChildren()
local max = #players
num = num + 1
if num > max then
num = 1
end
local player = players[num]
camera.CameraSubject = player.Character.Humanoid
status.Text = player.Name
end)
frame.Changed:Connect(function()
if not frame.Visible then
local Players = game:GetService(“Players”)
local localPlayer = Players.LocalPlayer
local function resetCameraSubject()
if workspace.CurrentCamera and localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
workspace.CurrentCamera.CameraSubject = humanoid
end
end
end
end
end)