Server or Client HeartBeat

I currently have a HeartBeat event running code to move a pet

function module.MovePet(Player, BodyPosition, HRP, Gyro, Pet)
	local Check = false
	
	local function MoveLoop()
		
	if Players:FindFirstChild(Player.Name) and Workspace_Pets:FindFirstChild(Pet.Name) then
	BodyPosition.Position = (HRP.CFrame * CFrame.new(4, 3, 4)).p
	Gyro.CFrame = HRP.CFrame + HRP.CFrame.lookVector  * 1 
	else
		Check = true
	end
	
	end
	
	local Heart = RunService.Heartbeat:connect(MoveLoop)
	
	if Check == true then Heart:Disconnect() end
	
	end

should this be handled on the client and then a remote event sends the data to adjust the Body Movers with remote events, or should I do it all on the server or another method?

either way code is going to be ran rapidly though, which way is best

Just tested changing the movers locally and it works perfectly thanks for all the help, I wish I could mark multiple people as the solution but I marked @EmilyBendsSpace as it was most in-depth, thanks

I would run it on the server, as a remote event is going to take a bit of time to get to the server, and with multiple people the remote event will have a ton of data going back and forth. You should just use a while wait() do loop.

3 Likes

You can use;

  • Weld,
  • BodyMovers,
  • Constraints,

and a LocalScript to control it’s movement.

2 Likes

I would choose to animate it and move it on the client and further replicate it to other clients via the server. This ensures the smoothest animation from point to point because oftentimes the server will lag in cases of efficiently communicating where the part (or pet) should be.

Such can be demonstrated with the tween function; if you were to run the tween on the server it would look far more choppy to clients rather than if you just tween on the client individually. While this practice can be bogged down by latency, the server would also result in latency and there’s not really a way to circumvent such a thing, so you might as well just ensure the end product looks good on the clients once it arrives. :smile:

If you’re worried about security in this situation you may need to instate some sanity checks on the server that way the client can’t just tell the server “hey send this here” without any kind of resistance. Once you get that down, you should be all good to smooth stuff out on the client :+1:

2 Likes

I would give the player’s client network ownership of the pet, and set the BodyMover goals from the player’s client via LocalScript. I see no reason to burden the server with all the pet following logic for all players. The BodyMovers will take care of making the movement smooth on all clients, and the advantage of giving the player local control, beside distributing the load, is that it will be the most responsive to their Character’s movement this way, the pet won’t lag behind your character by the client-server-client round-trip latency.

I agree with TrippyV that server-side validation is all you need if there are cheating or exploit concerns.

7 Likes

The players already had network ownership, I didn’t know that they could move it locally though

1 Like