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

Why does this script work for animations and walk speed?

Asked by
2mania 14
2 years ago

I have not done a lot of scripting with animations so I just wanted to ask how and why this script works (Pls break down the script) ~~~~~~~~~~~~~~~~~ local UIS = game:GetService('UserInputService') local Player = game.Players.LocalPlayer local Character = Player.Character

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 25 local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://10867310905' 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 PlayAnim:Stop() end end) ~~~~~~~~~~~~~~~~~

0
this is a scripting helper page,not "how scripts work" or a scripting tutorial page man lamgogo 56 — 2y
0
We are helping them understand the script Iamgogo... scripting helpers is about helping with anything regarding scripts Kingu_Criminal 205 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Alright, so first of all

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

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. 
    if input.KeyCode == Enum.KeyCode.LeftShift then 
        Character.Humanoid.WalkSpeed = 25 
        local Anim = Instance.new('Animation')  
        Anim.AnimationId = 'rbxassetid://10867310905'   
        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 
        PlayAnim:Stop() 
    end 
end)

I will break it into 2 parts. Explaining inputBegan and inputEnded

Inputbegan registers when they press any key. This script checks if the key they pressed was the Left shift. If it was, then it increases their walkspeed. Then it creates a new animation, sets the ID (the animation it will play) and loads the animation. after loading, it plays.

InputEnded registers when any type of input ends. So the script checks what input ended, which is the leftShift. Then it sets their walkspeed back to normal, and the animation is stopped.

If this answer helped you, then please accept it and upvote it. If you want to talk more about scripting, message me on iNi#2338

Ad

Answer this question