I have tried making the fly script work better on mobile other than using context action service but the problem is when I move and then become idle I would still go in the same direction. For example if I move forward and then try to stop I still keep going. Any help would be greatly appreciated since I am a little confused on why it is happening. It would not print ended when I become idle.
local Tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HumanRootPart = character:WaitForChild("HumanoidRootPart")
local cam = game.Workspace.CurrentCamera
local Debris = game:GetService("Debris")
local pressed = false
local BodyVel
local BodyGyro
local Force = 2500000
local RunService = game:GetService("RunService")
local debounce = false
local RemoteEvent = Tool:WaitForChild("RemoteEvent")
local camConnW
local camConnA
local camConnS
local camConnD
local RunService = game:GetService("RunService")
local GetMoveVector = require(player:WaitForChild("PlayerScripts").PlayerModule:WaitForChild("ControlModule"))
local WPressed = "WFoward"
local function foward(Vector)
if Vector.z >= -1 and Vector.z < 0 then
camConnW = cam:GetPropertyChangedSignal("CFrame"):Connect(function()
if Vector.z >= -1 and Vector.z < 0 then
BodyVel.Velocity = cam.CFrame.LookVector * 65
end
end)
print("began")
else
if camConnW then
camConnW:Disconnect()
camConnW = nil
end
BodyVel.Velocity = Vector3.new(0,0,0)
print("ended")
end
end
local APressed = "ALeft"
local function left(Vector)
if Vector.x >= -1 and Vector.x < 0 then
camConnA = cam:GetPropertyChangedSignal("CFrame"):Connect(function()
if Vector.x >= -1 and Vector.x < 0 then
BodyVel.Velocity = cam.CFrame.RightVector * -65
end
end)
print("began")
else
if camConnA then
camConnA:Disconnect()
camConnA = nil
end
BodyVel.Velocity = Vector3.new(0,0,0)
end
end
local SPressed = "SBack"
local function back(Vector)
if Vector.z > 0 then
camConnS = cam:GetPropertyChangedSignal("CFrame"):Connect(function()
if Vector.z > 0 then
BodyVel.Velocity = cam.CFrame.LookVector * -65
end
end)
print("began")
else
if camConnS then
camConnS:Disconnect()
camConnS = nil
end
BodyVel.Velocity = Vector3.new(0,0,0)
end
end
local DPressed = "Dright"
local function right(Vector)
if Vector.x > 0 then
camConnD = cam:GetPropertyChangedSignal("CFrame"):Connect(function()
if Vector.x > 0 then
BodyVel.Velocity = cam.CFrame.RightVector * 65
end
end)
print("began")
else
if camConnD then
camConnD:Disconnect()
camConnD = nil
end
BodyVel.Velocity = Vector3.new(0,0,0)
end
end
Tool.Activated:Connect(function()
if not pressed then
pressed = true
BodyVel = Instance.new("BodyVelocity")
BodyGyro = Instance.new("BodyGyro")
BodyGyro.Parent = HumanRootPart
BodyGyro.MaxTorque = Vector3.new(1, 1, 1)*10^6;
BodyGyro.P = 10^6;
BodyVel.Parent = HumanRootPart
BodyVel.P = 10^5;
BodyVel.MaxForce = Vector3.new(Force,Force,Force)
BodyVel.Velocity = Vector3.new(0,0,0)
RunService.Heartbeat:Connect(function()
if not debounce then
debounce = true
if BodyGyro and BodyGyro.Parent then
BodyGyro.CFrame = cam.CFrame
end
wait(0.01)
debounce = false
end
end)
while wait(0.1)do
local Vector = GetMoveVector:GetMoveVector()
if Vector == Vector3.new(0, 0, 0) then
BodyVel.Velocity = Vector3.new(0,0,0)
--print("Idle")
if camConnW and camConnA and camConnS and camConnD then
camConnW:Disconnect()
camConnA:Disconnect()
camConnS:Disconnect()
camConnD:Disconnect()
end
elseif Vector.z >= -1 and Vector.z < 0 then
foward(Vector)
elseif Vector.z > 0 then
back(Vector)
elseif Vector.x >= -1 and Vector.x < 0 then
left(Vector)
elseif Vector.x > 0 then
right(Vector)
end
end
elseif pressed then
pressed = false
BodyGyro:Destroy()
BodyVel:Destroy()
if camConnW then
camConnW:Disconnect()
camConnW = nil
end
if camConnA then
camConnA:Disconnect()
camConnA = nil
end
if camConnS then
camConnS:Disconnect()
camConnS = nil
end
if camConnD then
camConnD:Disconnect()
camConnD = nil
end
end
end)