Having mouse position be sent to the server

I already figured that the way to do it would be using a remote event, but that’s where the problem is.
My code looks for the position of the mouse constantly until the player lets go of m1:

Termination = RunService.Heartbeat:Connect(function()
			if player.Character then
				if player.Character.HumanoidRootPart then
					player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position + Mouse.Hit.LookVector)
				end
			end
			if not On then
				Termination:Disconnect()
			end
		end)

I fear that using remote events constantly wouldn’t be a good idea at all, as that would mean that there could possibly be many hundreds of them fired per second in one server in a matter of seconds.

I can’t do it locally because it doesn’t show the player turning on the server side, so other players can’t see where the player is aiming their attack.

How would I do this effectively?

1 Like

You could still use RemoteEvents, just add a cooldown on the client so it doens’t fire too often.

local lastUpdate = 0

Termination = RunService.Heartbeat:Connect(function()
	local now = os.clock()
	if player.Character and (now - lastUpdate) > .5 then
		lastUpdate = now
		if player.Character.HumanoidRootPart then
			player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position + Mouse.Hit.LookVector)
		end
	end
	if not On then
		Termination:Disconnect()
	end
end)
1 Like

It kind of works but having that cooldown makes it really really choppy.

Obviously I could mess around with the cooldown, but if I make it too little/fire the event too much, I don’t think it would be good.

1 Like

Lowering the cooldown will not be a problem. I use a head rotation system that fires a remote event every small fraction of a second.

2 Likes

This is the approach that other community-made packages take like CharacterRealism take and it looks smooth.

1 Like

I used @Lava_shield’s solution, though I’m not sure how stable it will be in the long term.

I used @yieldlua’s solution also because it looks cool.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.