So technically, I got this script that once you press W (on pc) it speeds up and animations plays. But on mobile it doesnt work so how do i make the script run for mobile players?
–Please find me a solution to my problem, my brain is going to explode ![]()
Thanks, Both ![]()
Code:
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local maxSpeed = 35
local maxJump = 20
local acceleration = 0.08
local currentSpeed = 18
local currentJump = 30
local currentAnimSpeed = 0.4
local isAccelerating = false
local isRunning = false
local runSound = game.SoundService.Running
runSound.PlaybackSpeed = currentSpeed / maxSpeed
local function increaseSpeed()
if currentSpeed < maxSpeed then
currentSpeed = currentSpeed + acceleration
currentAnimSpeed = currentAnimSpeed + (acceleration / maxSpeed)
else
currentSpeed = maxSpeed
currentAnimSpeed = 1.1
isAccelerating = false
end
Character.Humanoid.WalkSpeed = currentSpeed
Character.Humanoid.JumpPower = currentSpeed * 1.18 -- Increase jump power with speed
PlayAnim:AdjustSpeed(currentAnimSpeed)
runSound.PlaybackSpeed = currentSpeed / maxSpeed -- Adjust playback speed based on current speed
end
local function increaseJump()
if currentJump < maxJump then
currentJump = currentJump + acceleration
else
currentJump = maxJump
currentAnimSpeed = 1.1
isAccelerating = false
end
Character.Humanoid.JumpPower = currentJump
end
function ToggleAnimationAndSound(shouldPlay)
if shouldPlay then
if not PlayAnim.IsPlaying then
PlayAnim:Play()
end
if not runSound.IsPlaying then
runSound:Play()
end
else
PlayAnim:Stop()
runSound:Stop()
end
end
local leftControlDown = false
UIS.InputBegan:Connect(function(Key,IsTyping)
if IsTyping then return end
if Key.KeyCode == Enum.KeyCode.W then
isRunning = true
isAccelerating = true
local Anim = script.SprintAnim
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
ToggleAnimationAndSound(true)
print('Running')
elseif IsTyping.KeyCode == Enum.KeyCode.LeftControl then
leftControlDown = true
end
end)
UIS.InputEnded:Connect(function(Key,IsTyping)
if IsTyping then return end
if Key.KeyCode == Enum.KeyCode.W then
Character.Humanoid.WalkSpeed = 13
Character.Humanoid.JumpPower = 30
ToggleAnimationAndSound(false)
currentSpeed = 13
currentAnimSpeed = 0.4
isAccelerating = false
isRunning = false
print('Running stopped')
elseif Key.KeyCode == Enum.KeyCode.LeftControl then
leftControlDown = false
end
end)
function ToggleRunningIfAirborne()
if Character.Humanoid.FloorMaterial == Enum.Material.Air or leftControlDown then
ToggleAnimationAndSound(false)
elseif isRunning then
ToggleAnimationAndSound(true)
end
end
game:GetService('RunService').Heartbeat:Connect(function()
ToggleRunningIfAirborne()
if isAccelerating then
increaseSpeed()
end
end)