Runservice lag spike

  1. What do you want to achieve?
    Fix the odd lag spike that occurs when I jump/move upward on the Y axis

  2. What is the issue?
    Everytime i jump/move upward on the Y axis my game just lags until I hit the floor again.
    and its only when I move upward.

  3. What solutions have you tried so far?
    changing the method of using Runservice like “Renderstepped or PreRender”, but Heartbeat was the only one that seemed to work smoothly.

stopping the heartbeat when the player moves on the Y axis (which worked but it was for debug purposes to actually confirm that that was the reason it was bugging out).

Checking it if was the FireEvent function, but nothing changed, it really seemed to be on the client side.

Checking other Scripts that had a potential cheap line of code that made the game lag, such ass Jumping statements. but noticing after turning this one off it was gone.

Client:




local player = game.Players.LocalPlayer
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
local torso = character:FindFirstChild("Torso")
local neck = torso:WaitForChild("Neck")
local right = torso:WaitForChild('Right Shoulder')
local left = torso:WaitForChild("Left Shoulder")
local RS = game.ReplicatedStorage


local y = neck.C0.Y
local z = right.C0.X



run.Heartbeat:Connect(function()
	local camdirec = root.CFrame:ToObjectSpace(cam.CFrame).LookVector
		neck.C0 = CFrame.new(0,y,0) * CFrame.Angles(0,math.rad(180),0) * CFrame.Angles(0,-camdirec.X, 0) * CFrame.Angles(-camdirec.Y,0,0)
		neck.C0 = neck.C0 * CFrame.Angles(math.rad(-90),0,0)

		right.C0 = CFrame.new(z,0.5,0) * CFrame.Angles(0,math.rad(180),0) * CFrame.Angles(0,-camdirec.X, 0) * CFrame.Angles(-camdirec.Y,0,0)
		right.C0 = neck.C0 * CFrame.Angles(0,math.rad(-90),math.rad(-90)) + Vector3.new(1,-0.5,0)

		left.C0 = CFrame.new(z,0.5,0) * CFrame.Angles(0,math.rad(180),0) * CFrame.Angles(0,-camdirec.X, 0) * CFrame.Angles(-camdirec.Y,0,0)
		left.C0 = neck.C0 * CFrame.Angles(0,math.rad(90),math.rad(90)) + Vector3.new(-1,-0.5,0)

		RS.Locals.Remotes.Player.ArmMovement:FireServer(neck.C0,right.C0,left.C0)

end)

Server: (if its needed)


game:GetService("ReplicatedStorage").Locals.Remotes.Player.ArmMovement.OnServerEvent:Connect(function(plr,txt,txt2,txt3)
	local char = plr.Character
	local torso = char:FindFirstChild("Torso")
	torso:WaitForChild("Neck").C0 = txt
	torso:WaitForChild("Right Shoulder").C0 = txt2
	torso:WaitForChild("Left Shoulder").C0 = txt3
end)

the amount of lag this script has given me and the amount of times I had to work my way around it is insane.

2 Likes

I manage to fix the issue myself, it was the startercharacter player and its Animsaves model inside, i believe there was too much inside of there for the client to handle on certain events.

1 Like

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