I made him print the camera variable, and it wasn’t nil. His problem seems to not be related to the camera being nil from what I gathered, it’s that the player and playerName variable is nil. I do agree that OP didn’t change the CameraType, so I agree with that statement.
From the server, the workspace.CurrentCamera
returns the Camera
in Workspace
. This is not the same camera the clients use.
- With FireClient the first argument is everytime the client who will receive the request and isn’t an argument sent to the client.
- The second argument is the server Camera but you can’t and that literally return nil.
- The third argument is the player at who you send the request. Why?
Here you have three arguments but in fact you sent two arguments. You sent camera
and viewPlayer
.
So you print camera
(nil), Player Instance
and nil
.
local players = game:GetService("Players")
local player = players.LocalPlayer -- Only in a LocalScript
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.viewEvent
local camera = workspace.CurrentCamera -- Only in a LocalScript
event.OnClientEvent:Connect(function()
local viewPlayer = player.Name
local character = workspace:FindFirstChild(viewPlayer)
if character then
cam.CameraSubject = character.Humanoid
end
end)
and server side:
event:FireClient(viewPlayer)
I think you wanna make a “spectate” but you make the client watch itself, that won’t change anything for him.
Alright, now I am not getting an error and it doesn’t work as how it is meant to be. It is still setting the camera to your player not the targeted player.
Because you set it that way. Like @NiniScripterXQc said:
event:FireClient(viewPlayer, camera, viewPlayer)
viewPlayer
is the player who will spectate the other player.
Do not input the camera.
For your third input, you sent viewPlayer
again?
This is why you cannot spectate anyone else.
local Players = game:GetService("Players")
local PlayerFromName = require(script.Parent.Parent.PlayerFromName)
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.viewEvent
return function (admin, splitMessage)
local viewPlayerName = splitMessage[2]
local viewPlayer = PlayerFromName(admin, viewPlayerName)
if not viewPlayer then
return
end
event:FireClient(Players[admin.Name], viewPlayer)
end
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.viewEvent
event.OnClientEvent:Connect(function(player)
local cam = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
cam.CameraSubject = character:WaitForChild("Humanoid")
end)
Thank you, I understand where I went wrong.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.