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

Different run and walk animations?

Hello, I would like to have help on making a script. I would like to have a sprint script that will play a walking animation at default speed then when pressed "Shift" it will increase the player speed while also playing a run animation. I don't know how to go about doing this, I've had trouble for the longest time.

2 answers

✓ Accepted answer

For the walking animation you could use roblox's default animation script and changing the animation Id.

For making it so that when the player presses shift you would play a running animation you could use the UserInputService to detect their input.

https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan

https://developer.roblox.com/en-us/api-reference/class/AnimationTrack

--Something along the lines of this in a local script because UserInputService only works on the client

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

UserInputService.InputBegan:Connect(function(key, gameProccessed)
	if gameProccessed == false then
		if key.UserInputType == Enum.UserInputType.Keyboard then
			if key.KeyCode = Enum.KeyCode.LeftShift then
				local animation = Instance.new("Animation")
				animation.AnimationId = "the asset id of the animation"
				local runningAnimation = character:WaitForChild("Humanoid"):LoadAnimation(animation)
				runningAnimation:Play()
				character.Humanoid.WalkSpeed = "how fast you want them to run"
				--If you wanted them to stay running while shift is held down
				--[[while UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) do
					runningAnimation:Play()
					wait(Length of running animation)
				end]]
			end
		end
	end
end)

You need to copy Animator from your character and put him in StarterCharacterScripts and then change animations there (in file and in script) to rbxassetid://YourAnimationId

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