Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- zen made dis pls give me credit
- -- i added some notes just in case you got confused, also you can change the default playerspeed when the player is done running
- -- change the button size, color, and image to whatever you want.
- -- Get the ImageButton
- local button = script.Parent
- -- Get the UserInputService
- local userInputService = game:GetService("UserInputService")
- -- Check if the platform is mobile
- local isMobile = userInputService.TouchEnabled
- -- Hide the button if the platform is not mobile
- if not isMobile then
- button.Visible = false
- end
- -- Variables for the hold-to-run animation
- local holdToRunEnabled = false
- local holdToRunStartTime = 0
- local holdToRunThreshold = 0.5 -- Adjust this value to change the hold time required to trigger the animation
- -- Define the desired speed when the button is pressed
- local runSpeed = 32 -- Adjust this value to change the running speed
- -- Define the animation ID for the running animation
- local runAnimationId = "rbxassetid://13774142136" -- Replace with the actual animation ID
- -- Store the running animation track
- local runAnimationTrack
- local playerspeed = 16 -- Change this to your default game speed, 16 is the normal. - zen
- -- Function to handle button press and release events
- local function onButtonInput(inputObject)
- local player = game.Players.LocalPlayer
- local character = player.Character
- if character then
- local humanoid = character:FindFirstChildOfClass("Humanoid")
- if isMobile then
- -- On mobile, use TouchStarted and TouchEnded events
- if inputObject.UserInputType == Enum.UserInputType.Touch then
- if inputObject.UserInputState == Enum.UserInputState.Begin then
- holdToRunEnabled = true
- holdToRunStartTime = tick()
- humanoid.WalkSpeed = runSpeed
- if humanoid:GetState() == Enum.HumanoidStateType.Running then
- if not runAnimationTrack then
- -- Load and play the running animation
- local animation = Instance.new("Animation")
- animation.AnimationId = runAnimationId
- runAnimationTrack = humanoid:LoadAnimation(animation)
- runAnimationTrack:Play()
- else
- -- Resume the running animation if it was previously paused
- runAnimationTrack:AdjustSpeed(runSpeed / humanoid.WalkSpeed)
- runAnimationTrack:Play()
- end
- end
- elseif inputObject.UserInputState == Enum.UserInputState.End and holdToRunEnabled then
- holdToRunEnabled = false
- humanoid.WalkSpeed = playerspeed -- Restore default WalkSpeed
- -- Pause the running animation
- if runAnimationTrack then
- runAnimationTrack:AdjustSpeed(1)
- runAnimationTrack:Stop()
- end
- end
- end
- else
- -- On other platforms, use MouseButton1 event
- if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
- if inputObject.UserInputState == Enum.UserInputState.Begin then
- holdToRunEnabled = true
- holdToRunStartTime = tick()
- humanoid.WalkSpeed = runSpeed
- if humanoid:GetState() == Enum.HumanoidStateType.Running then
- if not runAnimationTrack then
- -- Load and play the running animation
- local animation = Instance.new("Animation")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement