I would like to have a player spectate another. I created the following demo to showcase a problem that I am having.
This code sends player 1’s camera to player 2, so that player 2 can see what player 1 is seeing. Both players are in First Person Mode camera. It seems like the character model of both players is not moving in the same orientation. More specifically when player 1 (right screen in gif) moves left or right, the character faces forward, however in player 2’s (left screen in gif) screen turns around as if the character has turned towards the moving direction. This is most evident by the tool/shadow being inconsistent for both players. Refer to the following gif and code.
fps-spectate.rbxl (55.9 KB)
-- ServerScriptService
game.ReplicatedStorage.PlayerCamera.OnServerEvent:Connect(function(player, cframe)
game.ReplicatedStorage.PlayerCamera:FireClient(
game.Players:WaitForChild("Player2"),
cframe
)
end)
-- StarterPlayer.StarterPlayerScripts
local localPlayer = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local function SetFirstPersonMode()
camera.CameraType = Enum.CameraType.Attach
localPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end
SetFirstPersonMode()
local tempCframe = nil
if localPlayer.Name == "Player1" then
print('Walk')
game:GetService("RunService").RenderStepped:Connect(function()
game.ReplicatedStorage.PlayerCamera:FireServer(workspace.CurrentCamera.CFrame)
end)
elseif localPlayer.Name == "Player2" then
print('Spectate player 1')
camera.CameraSubject = workspace:WaitForChild("Player1")
game.ReplicatedStorage.PlayerCamera.OnClientEvent:Connect(function(cframe)
tempCframe = cframe
end)
game:GetService("RunService").RenderStepped:Connect(function()
workspace.CurrentCamera.CFrame = tempCframe
end)
end