Weird laggy stuttering while flying

So i’m extremely new to making fly scripts and i have no idea what’s going on. I’ve been testing around for a couple hours trying to fix this issue with the stuttering and i dont know what is the issue. I’m trying to make my lockon system compatible with my flight system and it’s pushing me backwards whenever i come close to the player.
I would be very thankful if anyone could tell me what i am doing wrong and how this is happening.

Also the thing where it just changes up completely when i come close is just my ground check if i’m in the air or not. So that’s not the issue.

The code:

local function toggleFlight()
	char.Animate.Disabled = true
	
	local bodyGyro = Instance.new("BodyGyro", char.HumanoidRootPart)
	bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
	bodyGyro.P = 1000
	bodyGyro.CFrame = char.HumanoidRootPart.CFrame
	
	local bodyPosition = Instance.new("BodyPosition", char.HumanoidRootPart)
	bodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bodyPosition.P = 10
	bodyPosition.Position = char.HumanoidRootPart.Position
	runservice.RenderStepped:Connect(function()
		bodyGyro.CFrame = char.HumanoidRootPart.CFrame
		bodyPosition.Position = char.HumanoidRootPart.Position
	end)
	
	
	
	
end```

Any luck on fixing this issue? I’m having the same exact problem at the moment.

It looks like the issue only starts when you lock the camera.

At first you are flying smooth, then you lock the camera to the target, and it stutters.

So maybe its more of a camera issue, are you using a fast update, like a render stepped ?

Looks like a classic HumanoidStateType issue (these are usually pretty annoying). Roblox applies forces on your character based on the HumanoidStateType to keep it upright, so your body gyro is kinda wrestling against those forces whenever your character is on an angle (causing the shaking). Try changing the HumanoidStateType to Physics by doing Humanoid:ChangeState(Enum.HumanoidStateType.Physics) on the client to disable those forces (this may cause issues if you bump into parts however, not entirely sure) (also you’re gonna want to make sure you change the state back to Running when you’re done flying)

edit: emphasis that this must be done on the client, since you cannot change the state of a character that isn’t owned by the same network

I can’t speak for him, but I’m having a similar issue with my Flight + Lock On Systems and regardless of PlatformStand, AutoRotate, or Physics state changes/manipulations the stutter still exists. I’ve been kind of stumped on this issue myself for about a day now.

I just recently made custom swimming for a game so I can sympathize with how painful this stuff can be :sob:

If you have some sort of loop that’s constantly updating your orientation and stuff, I would suggest printing out the current humanoid’s state just as a sanity check to see if it’s actually in the state that you want

print(Humanoid:GetState())

I think I’ve fixed the issue with my flight and lock on systems atleast (I think), Wizard DM me if you want me to share with you what fixed it for me and hopefully it can for you to.

1 Like

You really should post your solution here to help others who might be having similar issues.

1 Like

I just came on and didn’t realize that this was going to be responded too. Hold on.

1 Like

This seemed to fix the issue, thank you brother.

1 Like

For sure, discord: dongorilliano :+1:

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