I seem to be having this issue with my mobile players.
At first I just thought my mobile players were confused, or didn’t know how to use the flying script, and for over a year, they complained, that flying (and swimming as it uses the same code) was causing them blink in and out, and crash the code.
Finally someone was able to get a console shot, and showed me that the players HRP, was getting a position of NAN. I had no idea what this meant, and scoured the internet with not much help.
I have experimented for the last few days, trying to narrow this down, and see where the problem is happening. Finally I realized it is happening in the modules of swim and fly and only when either inserting or manipulating the Thrust Force or Body Gyro.
Then I found this post and thought you might be of some help to me.
I am using a modified version of a flying script from the Roblox Gear Pompous, the Cloud - Roblox
(Which by the way, this Gear in a place by itself will unmodified will cause the NAN issue with mobile players)
Looking through the code, I don’t understand the physics of it enough to determine where the problem spot might be, so I thought I might ask you and post the piece of code, to see if you or anyone else might can see where the trouble might be.
local Camera = workspace.CurrentCamera
local CoordinateFrame = Camera.CoordinateFrame
local Movement = Vector3.new(0, 0, 0)
if Humanoid.MoveDirection.Magnitude > 0 then
local localControlVector = CFrame.new(Vector3.new(0,0,0),CoordinateFrame.lookVector*Vector3.new(1,0,1)):vectorToObjectSpace(Humanoid.MoveDirection+Vector3.new(0,.2,0))
Movement = CoordinateFrame:vectorToWorldSpace(localControlVector.Unit * Speed.Current)
Momentum = ((Momentum * Inertia) + Movement)
TotalMomentum = math.min(Momentum.Magnitude, Speed.Max)
local MomentumPercent = (TotalMomentum / Speed.Max)
local Tilt = ((Momentum * Vector3.new(1, 0, 1)).unit:Cross(((LastMomentum * Vector3.new(1, 0, 1)).unit))).y
if tostring(Tilt) == "-1.#IND" or tostring(Tilt) == "1.#IND" or Tilt == math.huge or Tilt == -math.huge or tostring(0 / 0) == tostring(Tilt) then
Tilt = 0
local AbsoluteTilt = math.abs(Tilt)
if AbsoluteTilt > 0.06 or AbsoluteTilt < 0.0001 then
if math.abs(LastTilt) > 0.0001 then
Tilt = (LastTilt * 0.96)
Tilt = 0
Tilt = ((LastTilt * 0.9) + (Tilt * 0.1))
LastTilt = Tilt
if TotalMomentum < 0.5 then
Momentum = Vector3.new(0, 0, 0)
TotalMomentum = 0
FlightGyro.CFrame = CFrame.new(Vector3.new(0,0,0),Torso.CFrame.lookVector * Vector3.new(1,0,1))
elseif TotalMomentum < 10 then
FlightGyro.CFrame = CFrame.new(Vector3.new(0,0,0),Momentum * Vector3.new(1,0,1))
FlightGyro.CFrame = (CFrame.new(Vector3.new(0,0,0), Momentum) * CFrame.Angles(0,0,(Tilt*-20)))
FlightVelocity.Velocity = Momentum --+ Vector3.new(0,JumpMomentum,0)
LastMomentum = Momentum