Hello, I want to create a spectating feature to my own game. However, I have encountered a problem.
The script used to have no problems at all, but from last few weeks on, the spectate function seems to not working properly.
This is the script:
local IsUse = false
Menu.Bar.Spectate.MouseEnter:Connect(function()
Menu.Bar.Spectate.ImageColor3 = Color3.fromRGB(200,200,200)
end)
Menu.Bar.Spectate.MouseLeave:Connect(function()
Menu.Bar.Spectate.ImageColor3 = Color3.fromRGB(255,255,255)
end)
Menu.Bar.Spectate.MouseButton1Click:Connect(function()
if Mode ~= "Spectate" or IsUse then
Mode = "Spectate"
IsUse = false
spawn(function()
ResetLightings()
end)
if game.ReplicatedStorage.PlayerStatus[game.Players.LocalPlayer.Name].Value == "Lift" then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPos.Cam2Pos.CFrame * CFrame.Angles(math.rad(-12),math.rad(0),math.rad(0))
else
Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
Camera.CameraType = Enum.CameraType.Custom
end
print(Camera.CameraSubject:GetFullName())
print(Camera.CameraType)
Open(SpectateSize,Spectate,"Spectate")
if Mode == "Spectate" then
MainFrame.PlayerList:ClearAllChildren()
script.Parent.Parent.UIListLayout:Clone().Parent = MainFrame.PlayerList
script.Parent.Parent.UIPadding:Clone().Parent = MainFrame.PlayerList
local players = RS.RemoteFunction.GetRoundPlayers:InvokeServer()
for i,v in pairs(players) do
if v ~= game.Players.LocalPlayer.Name then
local Clone = script.Parent.Parent.Extra.SpectatePlayer:Clone()
Clone.Parent = MainFrame.PlayerList
Clone.Name = v
Clone.Text = v
Clone.MouseButton1Click:Connect(function()
IsUse = true
Close()
if workspace:FindFirstChild("Map") then
LocalLightings(workspace.Map)
end
Camera.CameraSubject = game.Players[v].Character.Humanoid
Camera.CameraType = Enum.CameraType.Custom
end)
end
end
end
else
Mode = nil
IsUse = false
Close()
end
end)
The system works like this:
When the player presses the “Spectate” button, the camera always go back to the character, then after adjusting some lighting properties, the list of players show up.
However, when I click the “Spectate” button again while I am spectating another player, the camera doesn’t go back to the character as shown:
https://gyazo.com/61e3285241bbb8f4bfaa98c4d8614367
I have tried looking up solutions both here and ROBLOX Developer Hub. I have asked my friends which are professional as scripting as well. Unfortunately, the problem cannot be solved.
I am not sure if it is an Engine Bug, as the camera is also manipulated in other scripts, not just this one.