Player To Camera Script without firing 100 remotes every ms?

Hello,
I’m trying to make a system where the player looks in the direction the camera is facing. I don’t know how to do it without firing a remote event every ms / s. I’m currently using my old topic / post to create this effect.

In Mad City, when you look around, it replicates to every client in the game, really showing detail in that game.
Here is a video showing that sick feature.

I’m using a sensitivity script inside my game (custom camera stuff), and I’m making the players root part look in the direction the camera is facing for reasons.

If you need more detail into this, let me know.

Unacceptable Answer(s)
  • No lerping the players torso orientation every 2 seconds (or something like that)

There isn’t really a need for remote events (unless you’re doing it for security) because if the rotation of the character is changed in the client it will also automatically change for the server, because the CFrame of the character always replicates even with filtering enabled.

1 Like

This is not true. The only thing clients are authoritative of replicating is physics by right of network ownership. CFrame sets do not replicate as they are not physics changes.

3 Likes

So did Mad City just fire events every second? Did they use SetNetworkOwner? Because I don’t know how to use Network Owner stuff

1 Like

Yes. You don’t have to update it every ms though, just do it every frame, but only when the user moves the camera through input

2 Likes

How would I use NetworkOwnership then? Roblox doesn’t allow full control over it.

In this case there’s no reason to set network ownership. If I were going to do it I’d probably edit Roblox’s camera module to only replicate when camera rotation is changed and/or if there’s any new intersections to line of sight (LOS), but if you want it to be quick:

local ReplicationRemote = game:GetService("ReplicatedStorage"):WaitForChild "Remote" --> Change this
local CameraModule, IO  = { }, game:GetService("UserInputService")

function CameraModule.new(Player, Camera)
	local this = { }
	this.lastAng = nil
	
	local function getHitPos()
		local pos = IO:GetMouseLocation()
		return game.Workspace:FindPartOnRay(
			Ray.new(Camera.CFrame.p, Camera:ViewportPointToRay(pos.x, pos.y, 0).Direction * 1000),
			Player.Character
		)
	end
	
	Camera:GetPropertyChangedSignal("CFrame"):Connect(function ()
		local hit, pos = getHitPos() --> could use hit/pos to determine LOS intersection
		local eul = Camera.CFrame:toEulerAnglesXYZ()
		
		--> Not perfect, but from the following we can deduce we've rotated the camera
		if this.lastAng ~= eul then
			this.lastAng = eul
			
			--> Send it to server
			ReplicationRemote:FireServer(pos)
			
			--> Do it locally so client can see it instantly
				-- local changes & stuff
				-- stuf stuf
		end
	end)
	
	return this
end

return CameraModule
1 Like