Should a sprint and a roll be done by the server or client?

So, I currently have a sprinting system that is server sided by sending a remote event to the server when the player begins sprinting, and then I change their Humanoid.WalkSpeed on the server. I also have my rolling/dash system done on the server using the same method. I’ve seen some other people do sprinting and rolling/dashing on the client and am wondering which is the correct path to take.

3 Likes

The sync/animation will look better on client sided for that specific client. While others in server would look it a little laggy/unsync, comming from that other client

On server sided, probably all clients will see the “same reality” most accurately, while each client will experiment a little delay while using the dash.

Client sided, would be better if you “sanity check” the use of that function, and not rely on client when he/she can trigger it.

I think depends on your game, and how much u need that dash is in sync on server, or best performance for each client, even if other clients dont experiment it equally. And adding the server check to allow them or not to perform the dash
Thats just what I think

1 Like

It can (and should) just be done entirely on the client, no remote event needed.
This will remove any lag between pressing the sprint or dash button and seeing your character sprint or dash.

If your dash only has a character animation, i.e. it only plays an Animation and makes the character’s limbs move, then it’s still fine to keep it completely client-sided.
But if it has any trail or wind or whatever effects on it, then you need to tell the server you’re dashing, otherwise the client-server barrier will stop that.

Write a function that puts the effect on the character.
When the player dashes, first run the function on the player’s character, then fire a remote to say the character dashed.
The remote should bounce back the event to all players, but add which player just dashed.
When each client receives the remote, they should check whether they are the player dashing, and ignore it if it is so. Otherwise, they should run the function with the player’s character, so that the effect is given to that character on everyone’s screen.

Pseudocode:

-- client

local player = game.Players.LocalPlayer
local dashRemote = game.ReplicatedStorage.SomeoneDashed

function DashEffect(player)
	-- add windy effects to player.Character
	-- this only needs to be done for things that don't pass through the FE barrier
	-- whenever possible, test your game and don't add things here until you're sure you need to put them here to make them show up for other players
	wait(2)
	-- clean up windy effects
end

function SomeoneDashed(who)
	if who == player then return end -- ignore if server told you something you already know
	DashEffect(who)
end

function StartDash()
	local char = player.Character
	local torso = char.PrimaryPart
	
	coroutine.wrap(DashEffect)(player) -- don't let the wait() hold up the next part of this function
	
	dashRemote:Fire()
	-- since these are all just movement and the client has authority over
	-- where its character is, these don't need to go in DashEffect()
	local velocity = Instance.new("BodyVelocity", torso)
	velocity.Velocity = (torso.LookVector * Vector3.new(1, 0, 1)).unit * 20
	-- play character animation
	
	wait(2)
	velocity:Destroy()
end

-- server:
local dashRemote = game.ReplicatedStorage.SomeoneDashed
dashRemote.OnServerEvent:connect(function(...) dashRemote:FireAllClients(...)) end -- bounce to all other clients
-- security warning: an exploiter can fire this a bajillion times per second to make everyone else lag out when they try to make a ton of wind effects on the exploiter's character
3 Likes

do animations and effects on client and do server side stuff on server such as walkspeed, jumppower etc