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

Different run and walk animations? [closed]

Asked by 4 years ago
Edited 4 years ago

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.

Closed as Not Constructive by Block_manvn, Fifkee, and youtubemasterWOW

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by
Zrxiis 26
4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago

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