Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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()


3 comments

0

there a couple errors in there but i guess you could figure it out

0

The animation part doesnt work, but the sprinting does! Thanks a bunch man.

0

no problem

This discussion is preserved as it was. New answers, comments, and votes are closed.