How to get camera CFrame from server?

I am working on an FPS game, and I need to get a player’s camera CFrame for shooting. My only worry is that the client with the aid of a hack client, could lie about their camera’s position to wreck the game. The player is locked in first-person. Also, I get how I could get the camera’s POSITION, by just getting the head’s position, but how would I know how to get their lookVector? Any help is appreciated. Thanks!

Use a remote event.

camCF = workspace.CurrentCamera.CFrame -- this returns the lookvector and the position of the camera

remoteEvent:FireServer(camCF)

Yes, but my worry is that hack-clients can change the camera CFrame to a CFrame from across the map, so I am wonder how do I make sure that what I am recieving is what is real?

There is no 100% reliable way of getting information from the client. You may want to just secure your remote events to prevent kill all scripts. Things like aimbot are impossible to prevent though, as anything done on the client side can be faked. I would go with what @Intencidy said and use remote events to pass the position of the camera.

1 Like

I guess you can try firing twice in a second or less and compare on the server if the difference between the 2 received CFrames is way too big.

EDIT: When I said firing twice I meant fire 2 separate events.

There really isn’t a good way to get camera position from the server. Just do it from the client with security. Such as checking the camera position with the player’s head. This way you can ensure the camera is at the players head.

how do i get somebodies password from my computer? Now that might be a stretch but what im trying to get at is that only the client knows what its camera cframe is. On the server it doesnt exist. You would have to simply trust the client to get the cframe

If you don’t want to use remotes event then, at the server script of the gun or fps, just get the player’s head and it’s obvious to get the lookvector by the head’s CFrame.

Head.CFrame.LookVector

Edit: This is the only way if you want to prevent doing this from the client. I still recommend using RemoteEvents since it’s the only way for getting infomation from the client, and it’s faster. I don’t recommend doing on the server but i think that it’s slower to do on the server because of network delays.