How do I make this script so that if you hold left shift, you will run and play an animation?
Asked by
5 years ago Edited 5 years ago
I got this from a tutorial, since I'm a beginner scripter, but I tried to script it so when you hold it, you'll run, and an animation plays, and when you stop, it goes back to the default animation and walk speed, but I can't seem to script it that way, can someone help me? That would be nice. If you think this question is not constructive, I'll take it down, here is the script.
01 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
02 | local character = player.character or player.CharacterAdded:Wait() |
03 | local humanoid = character:WaitForChild( "Humanoid" ) |
04 | local uis = game:GetService( "UserInputService" ) |
05 | local anim = Instance.new( "Animation" ) |
08 | function onKeyPressed(inputObject, gameProcessEvent) |
09 | if inputObject.KeyCode = = Enum.KeyCode then |
10 | humanoid:LoadAnimation(anim):Play() |
11 | humanoid.WalkSpeed = 16 * 2 |
14 | uis.InputBegan:Connect(onKeyPressed) |