I’m thinking about giving up I seriously can’t figure out why the CameraSubject wont change
I’m trying to get it to Spectate another player, but it doesn’t go anywhere
local players = game:GetService("Players")
local spectateframe = script.Parent:WaitForChild("spectateframe")
local nextbutton = spectateframe:WaitForChild("next")
local lastbutton = spectateframe:WaitForChild("last")
local exitbutton = spectateframe:WaitForChild("exit")
local clickbutton = script.Parent:WaitForChild("spectatebutton")
local spectatelabel = spectateframe:WaitForChild("playerspectating")
local currentcamera = workspace.CurrentCamera
local char = players.LocalPlayer.Character or players.LocalPlayer.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local isSpectating = false
local currentIndex = 1
local playerList = {}
local function UpdatePlayers()
local newplayerlist = {}
for i, plr in pairs(game.ReplicatedStorage.players:GetChildren()) do
if plr.Name ~= game.Players.LocalPlayer.Name then
print("working")
table.insert(newplayerlist, plr.Name)
end
end
playerList = newplayerlist
end
local function UpdateSpectator()
local foundPlayer = players:FindFirstChild(playerList[currentIndex])
if foundPlayer then
print("found player")
spectatelabel.Text = "Spectating: "..foundPlayer.Name
print("switching camerasubject")
currentcamera.CameraType = Enum.CameraType.Watch
currentcamera.CameraSubject = foundPlayer.Character
print(foundPlayer)
print(foundPlayer.Character)
print(currentcamera.CameraSubject)
end
UpdatePlayers()
end
local function NextPlayer()
if currentIndex < #playerList then
currentIndex += 1
else
currentIndex = 1
end
UpdateSpectator()
end
local function LastPlayer()
if currentIndex > 1 then
currentIndex -=1
else
currentIndex = #playerList
end
UpdateSpectator()
end
local function QuitSpectate()
isSpectating = false
currentcamera.CameraSubject = hum
currentIndex = 1
spectateframe.Visible = false
end
clickbutton.MouseButton1Click:Connect(function()
if game.ReplicatedStorage.roundstarted.Value == true then
isSpectating = true
spectateframe.Visible = isSpectating
UpdatePlayers()
UpdateSpectator()
end
end)
nextbutton.MouseButton1Click:Connect(NextPlayer)
lastbutton.MouseButton1Click:Connect(LastPlayer)
exitbutton.MouseButton1Click:Connect(QuitSpectate)