I’m trying to make a spectate system but when I go to assign the CurrentCamera to another player, it does lose focus on the local player, but never focuses on the player it’s supposed to. It just kind of freezes.
I can confirm that it is assigning the correct player as the text label that shows the targets username does in fact show what it’s supposed to. I get the username like so:
Have you tried checking the CameraSubject property of the camera AFTER it loses the focus? If it is set to nil then there’s some other script conflicting and resetting it.
local cam = game.Workspace.CurrentCamera
local connection: RBXScriptConnection
local curplayer = 1
local curplayerhumanoid: Humanoid
function right()
local aliveplayers = game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer()
curplayer = curplayer + 1
if curplayer > #aliveplayers then
curplayer = 1
end
curplayerhumanoid = game.Players:GetPlayerByUserId(aliveplayers[curplayer]).Character:WaitForChild("Humanoid")
script.Parent.Parent.Parent.Parent.Spectator.Frame.Logo.Text = game.Players:GetNameFromUserIdAsync(aliveplayers[curplayer])
pcall(function()
connection:Disconnect()
end)
connection = curplayerhumanoid.Died:Connect(function()
aliveplayers = game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer()
curplayer = curplayer + 1
if curplayer > #aliveplayers then
curplayer = 1
end
if curplayer == #aliveplayers or #aliveplayers == 0 then
script.Parent.Parent.Parent.Parent.Spectator.Enabled = false
cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
else right() end
end)
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = game.Players:GetPlayerByUserId(aliveplayers[curplayer]).Character.Humanoid
end
function left()
local aliveplayers = game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer()
curplayer = curplayer - 1
if curplayer <= 0 then
curplayer = #aliveplayers
end
curplayerhumanoid = game.Players:GetPlayerByUserId(aliveplayers[curplayer]).Character:WaitForChild("Humanoid")
script.Parent.Parent.Parent.Parent.Spectator.Frame.Logo.Text = game.Players:GetNameFromUserIdAsync(aliveplayers[curplayer])
pcall(function()
connection:Disconnect()
end)
connection = curplayerhumanoid.Died:Connect(function()
aliveplayers = game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer()
curplayer = curplayer + 1
if curplayer > #aliveplayers then
curplayer = 1
end
if curplayer == #aliveplayers or #aliveplayers == 0 then
script.Parent.Parent.Parent.Parent.Spectator.Enabled = false
cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
else right() end
end)
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = game.Players:GetPlayerByUserId(aliveplayers[curplayer]).Character.Humanoid
end
script.Parent.MouseButton1Click:Connect(function()
if game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer() == nil then return end
local exists = false
for i, plr in pairs(game.ReplicatedStorage.RetrievePlayersInRound:InvokeServer()) do
if plr == game.Players.LocalPlayer.UserId then
exists = true
break
end
end
if exists then return end
script.Parent.Parent.Parent.Parent.Spectator.Enabled = not script.Parent.Parent.Parent.Parent.Spectator.Enabled
if script.Parent.Parent.Parent.Parent.Spectator.Enabled then
right()
left()
else
pcall(function()
connection:Disconnect()
end)
cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
script.Parent.Parent.Parent.Parent.Shop.Enabled = false
script.Parent.Parent.Parent.Parent.Inventory.Enabled = false
script.Parent.Parent.Parent.Parent.EventGui.Enabled = false
end
end)
script.Parent.Parent.Parent.Parent:WaitForChild("Spectator").Frame.Right.ImageButton.MouseButton1Click:Connect(right)
script.Parent.Parent.Parent.Parent.Spectator.Frame.Left.ImageButton.MouseButton1Click:Connect(left)
This is the entire spectate script, everything but the camerasubject aspect of it works as expected.
Thanks.
i would try making a loop with renderstepped and setting the camera subject through that. from the looks of it, the camera updtaes when you set the subject, but it doesnt stick, if you keep updatign it then it will stay on the subject ever yframe,.
The issue with this is that when I update the subject, the target is already far away from the player spectating them, but the camera doesn’t move at all.
Okay so it turns out that the reason the Camera wasn’t locking on the subject was because it was too far away as the spectate system works when the players are closer together. I’ll try to solve this by moving the maps closer