Fly tool for phone

So i’ve had my obby game out for a while (More than a year) and I just got told today that the fly tool that you get from a gamepass doesn’t work on phone/tablet. It works find on computer though.

How can I fix my code so that people on phone and tablet can use it?

I know it has something to do with Enum but i’m not 100% what I have to do

local Tool = script.Parent
local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")

while Character.Parent ~= game.Workspace do
	Player.CharacterAdded:Wait()
	Character = Player.Character or Player.CharacterAdded:Wait()
	HRP = Character:WaitForChild("HumanoidRootPart")
	Humanoid = Character:WaitForChild("Humanoid")
	Animate = Character:WaitForChild("Animate")
end

local idleAnim = Humanoid:LoadAnimation(script:WaitForChild("IdleAnim"))
local moveAnim = Humanoid:LoadAnimation(script:WaitForChild("MoveAnim"))
local lastAnim = idleAnim

local isFlying = false
local isEquipped = false
local movement = {forward = 0, backward = 0, right = 0, left = 0}

local bodyGyro
local bodyVel

local Particles = script:WaitForChild("CloudParticles")
local CloudParticles


local function createForces()
	if bodyVel or bodyGyro then
		return
	end
	local BodyGyro = Instance.new("BodyGyro")
	BodyGyro.maxTorque = Vector3.new(1, 1, 1)*10^6
	BodyGyro.P = 10^6
	bodyGyro = BodyGyro
	local BodyVel = Instance.new("BodyVelocity")
	BodyVel.maxForce = Vector3.new(1, 1, 1)*10^6
	BodyVel.P = 10^4
	bodyVel = BodyVel
end

local function setFlying(flying)
	createForces()
	isFlying = flying
	bodyGyro.Parent = isFlying and HRP or nil
	bodyVel.Parent = isFlying and HRP or nil
	bodyGyro.CFrame = HRP.CFrame
	bodyVel.Velocity = Vector3.new()
	
	Animate.Disabled = isFlying
	
	if (isFlying) then
		lastAnim = idleAnim
		lastAnim:Play()
	else
		lastAnim:Stop()
	end
end

local function onUpdate(dt)
	if (isFlying) then
		local cf = Camera.CFrame
		local direction = cf.rightVector*(movement.right - movement.left) + cf.lookVector*(movement.forward - movement.backward)
		if (direction:Dot(direction) > 0) then
			direction = direction.unit
		end
		bodyGyro.CFrame = cf
		bodyVel.Velocity = direction * Humanoid.WalkSpeed * 3
	end
end

local function onEquippedRequest()
	if (not Humanoid or Humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		return
	end
	if (isFlying) then
		setFlying(false)
		isEquipped = false
	elseif (isEquipped) then
		setFlying(true)
	end
end
	
local function onStateChange()
	if not isEquipped then	
		isEquipped = true
	else
		isEquipped = false
	end
end

local function movementBind(actionName, inputState, inputObject)
	if (inputState == Enum.UserInputState.Begin) then
		movement[actionName] = 1
	elseif (inputState == Enum.UserInputState.End) then
		movement[actionName] = 0
	end
	
	if (isFlying) then
		local isMoving = movement.right + movement.left + movement.forward + movement.backward > 0;
		local nextAnim = isMoving and moveAnim or idleAnim
		if (nextAnim ~= lastAnim) then
			lastAnim:Stop()
			lastAnim = nextAnim
			lastAnim:Play()
		end
	end
	
	return Enum.ContextActionResult.Pass
end

function RemoveIdleAnimation()
	local humanoid = Player.Character:WaitForChild("Humanoid")
	local AnimationTracks = humanoid:GetPlayingAnimationTracks()
	for _, track in pairs (AnimationTracks) do
		if track.Name == "ToolNoneAnim" then
			track:Stop()
		end
	end
end

function Initialize()
	RemoveIdleAnimation()
	if not isEquipped then
		local clonedParticles = Particles:Clone()
		CloudParticles = clonedParticles
		CloudParticles.Parent = Player.Character.PrimaryPart
		CloudParticles.Enabled = true
	else
		if CloudParticles then
			CloudParticles:Destroy()
		end
	end
	onStateChange()
	onEquippedRequest()
end


Tool.Equipped:Connect(Initialize)
Tool.Unequipped:Connect(Initialize)

game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterForward);
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackward);
game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft);
game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight);

game:GetService("RunService").RenderStepped:Connect(onUpdate)
1 Like