I don’t know how to access the mobile jump button so I can implement my flight script onto it. Can someone help
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local dashing = player:WaitForChild("Values"):WaitForChild("Dashing")
local jumpPower = 25
local maxHoldTime = 5
local gravityNeutralizer = Vector3.new(0, Workspace.Gravity * 2, 0)
local isHoldingJump = false
local holdStartTime = 0
local timeHeld = 0
local inAir = false
local bodyVelocity = nil
local flyingAnimation = nil
local flyingTrack = nil
local animationId = "rbxassetid://99626589634175"
flyingAnimation = Instance.new("Animation")
flyingAnimation.AnimationId = animationId
local function resetTimer()
if humanoid.FloorMaterial ~= Enum.Material.Air then
timeHeld = 0
if bodyVelocity then
bodyVelocity:Destroy()
bodyVelocity = nil
end
-- Stop the flying animation
if flyingTrack and flyingTrack.IsPlaying then
flyingTrack:Stop()
end
end
end
local function resetCharacter()
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
rootPart = character:WaitForChild("HumanoidRootPart")
bodyVelocity = nil
flyingTrack = nil
isHoldingJump = false
timeHeld = 0
inAir = false
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Space and dashing.Value == false then
if humanoid and inAir then
if timeHeld < maxHoldTime then
if not isHoldingJump then
holdStartTime = tick()
end
isHoldingJump = true
rootPart.Velocity = Vector3.zero
if not bodyVelocity then
bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = Vector3.new(0, jumpPower, 0)
bodyVelocity.Parent = rootPart
else
bodyVelocity.Velocity = Vector3.new(0, jumpPower, 0)
end
if not flyingTrack then
flyingTrack = humanoid:LoadAnimation(flyingAnimation)
end
if flyingTrack and not flyingTrack.IsPlaying then
flyingTrack:Play()
end
flyingTrack.DidLoop:Connect(function()
script.Flap:Play()
end)
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Space then
if isHoldingJump then
timeHeld = timeHeld + (tick() - holdStartTime)
isHoldingJump = false
if bodyVelocity then
bodyVelocity:Destroy()
bodyVelocity = nil
end
if flyingTrack and flyingTrack.IsPlaying then
flyingTrack:Stop()
end
end
end
end)
RunService.Heartbeat:Connect(function()
if isHoldingJump and humanoid and inAir then
local elapsedTime = tick() - holdStartTime
if timeHeld + elapsedTime <= maxHoldTime then
if bodyVelocity then
bodyVelocity.Velocity = Vector3.new(0, jumpPower, 0)
end
if flyingTrack and flyingTrack.IsPlaying then
local timeRemaining = maxHoldTime - (timeHeld + elapsedTime)
if timeRemaining <= 2 then
local speedMultiplier = math.max(timeRemaining / 2, 0.1)
flyingTrack:AdjustSpeed(speedMultiplier)
end
end
else
isHoldingJump = false
timeHeld = maxHoldTime
if bodyVelocity then
bodyVelocity:Destroy()
bodyVelocity = nil
end
if flyingTrack and flyingTrack.IsPlaying then
flyingTrack:Stop()
end
end
end
if inAir and bodyVelocity then
local moveDirection = Vector3.zero
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveDirection = moveDirection + rootPart.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveDirection = moveDirection - rootPart.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveDirection = moveDirection - rootPart.CFrame.RightVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveDirection = moveDirection + rootPart.CFrame.RightVector
end
if moveDirection.magnitude > 0 then
bodyVelocity.Velocity = moveDirection.Unit * 15 + Vector3.new(0, jumpPower, 0)
end
end
resetTimer()
end)
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Freefall then
inAir = true
elseif newState == Enum.HumanoidStateType.Landed then
inAir = false
resetTimer()
end
end)
player.CharacterAdded:Connect(function()
resetCharacter()
end)