Hello, I’m trying to make a command that makes the player view another player. But with the unview command, it says attempt to index nil with character. Any solutions?
commands.unview = function(player)
print(player)
game.ReplicatedStorage.RemoteEvents.ViewPlayer:FireClient(player,nil)
logEvent:FireAllClients(player.Name.." used 'unview'",false)
end
game.ReplicatedStorage.RemoteEvents.ViewPlayer.OnClientEvent:Connect(function(player,target)
local camera = workspace.CurrentCamera
if target ~= nil then
camera.CameraSubject = target.Character.Humanoid
else
camera.CameraSubject = player.Character.Humanoid
end
end)
You firing the player’s client with nil, then assuming you have a player value, which you don’t. Player is only for server event, and player is just “nil”, because that’s the only variable you sent over.
Let me explain
ClientEvent shows the variables you sent, which is nil.
When you fire the client, with Player, Nil, you’re firing that client, and sending over the value nil, you need to send the Player Value twice for it to work.
When you fire the client, there’s no player to specify because it’s being fired from the whole server. You need to send it as an arguement/variable through the remote event.
So, your code should be this:
commands.unview = function(player)
print(player)
game.ReplicatedStorage.RemoteEvents.ViewPlayer:FireClient(player,player,nil)
logEvent:FireAllClients(player.Name.." used 'unview'",false)
end