Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make this sprint script compatible on mobile devices?

Asked by
2_dew 7
3 years ago
Edited 3 years ago

Hey everyone! This is my first question on this forum, so sorry if anything is wrong or in the wrong format.

So, I have this thing in my game which allows you to sprint with the press of the shift button. It also plays an different animation while running.

Heres the full script, being parented in StarterCharacterScripts

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        Character.Humanoid.WalkSpeed = 35
        Character.Humanoid.JumpPower = 65
        local Anim = Instance.new("Animation")
        Anim.AnimationId = "rbxassetid://5686974800" 
        PlayAnim = Character.Humanoid:LoadAnimation(Anim)
        PlayAnim:Play()
    end
end)

UIS.InputEnded:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        Character.Humanoid.WalkSpeed = 16
        Character.Humanoid.JumpPower = 50
        PlayAnim:Stop()
    end
end)

Is there anyway I can program a mobile button to activate some variation of this script when being held down? If you need any more info to fix my problem, please ask!

1 answer

Log in to vote
-1
Answered by 3 years ago

put this is a gui button

script.Parent.MouseButton1Down:Connect(function(player)
local character = player.Character
if input.KeyCode == Enum.KeyCode.LeftShift then
        Character.Humanoid.WalkSpeed = 35
            Character.Humanoid.JumpPower = 65
            local Anim = Instance.new("Animation")
            Anim.AnimationId = "rbxassetid://5686974800"
            PlayAnim = Character.Humanoid:LoadAnimation(Anim)         
  PlayAnim:Play()
end)
script.Parent.MouseButton1Up:Connect(function(player)
local character = player.Character
Character.Humanoid.WalkSpeed = 16
     Character.Humanoid.JumpPower = 50
            PlayAnim:Stop()


0
there a couple errors in there but i guess you could figure it out catsalt29 57 — 3y
0
The animation part doesnt work, but the sprinting does! Thanks a bunch man. 2_dew 7 — 3y
0
no problem catsalt29 57 — 3y
Ad

Answer this question