I fire a remote event from the server to make my character run infinitely towards 1 direction, here is the LocalScript code:
local player = game.Players.LocalPlayer
local minWalkSpeed = nil
game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Game"):WaitForChild("unfreezePlayer").OnClientEvent:Connect(function(startingMinWalkSpeed)
if player.Character ~= nil then
if player.Character:FindFirstChild("Humanoid") then
minWalkSpeed = startingMinWalkSpeed
player.Character.Humanoid.WalkSpeed = minWalkSpeed
player.Character.Humanoid:Move(Vector3.new(1,0,0), false)
end
end
end)
As you can see in the video, the player stutters (only on the server). I found a workaround by adding the following code to the LocalScript:
while true do
wait()
if minWalkSpeed == nil then return end
if player.Character then
if player.Character.Humanoid then
local newVal = math.random(minWalkSpeed - 0.00001, minWalkSpeed + 0.00001) -- fixt stutters
player.Character.Humanoid.WalkSpeed = newVal
end
end
end
Weirdly enough, slightly modifying the player’s walkspeed every time solves this problem completely, the player’s movements are smoothly replicated on the server.
I don’t want to use such a tricky workaround though, does anyone know what’s going on? I think it has something to do with using a remote event, because when I tried the code without waiting for an event, everything went smoothly. There’s no extra code on the server, except for firing the remote event.
EDIT: I generate paths during running, when I run the code in lobby instead of these generated paths, the running no longer stutters. I think it might have something to do with Network Ownership? Still weird how the while loop fixes it.
EDIT 2: When I bring these paths closer to the lobby, it no longer stutters. There’s a huge position difference to make sure that players in the lobby don’t see the paths.