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

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.

01local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
02local character = player.character or player.CharacterAdded:Wait()
03local humanoid = character:WaitForChild("Humanoid")
04local uis = game:GetService("UserInputService")
05local anim = Instance.new("Animation")
06anim.AnimationId = "rbxassetid://5044642525"
07 
08function onKeyPressed(inputObject, gameProcessEvent)
09    if inputObject.KeyCode == Enum.KeyCode then
10        humanoid:LoadAnimation(anim):Play()
11        humanoid.WalkSpeed = 16*2
12    end
13end
14uis.InputBegan:Connect(onKeyPressed)

1 answer

Log in to vote
0
Answered by 5 years ago

Paste this into a starter charcter script:

01local character = game:GetService("Players").LocalPlayer.Character
02 
03local userInputService = game:GetService("UserInputService")
04userInputService.InputBegan:connect(function(input)
05    if input.UserInputType == Enum.UserInputType.Keyboard then
06        if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
07            character.Humanoid.WalkSpeed = 32
08        end
09    end
10end)
11 
12userInputService.InputEnded:connect(function(input)
13    if input.UserInputType == Enum.UserInputType.Keyboard then
14        if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
15            character.Humanoid.WalkSpeed = 16
16        end
17    end
18end)
0
I get these three errors: 19:47:49.343 - Walkspeed is not a valid member of Humanoid, 19:47:50.894 - Keycode is not a valid member of InputObject and 19:48:43.826 - Touched is not a valid member of Script Abysmallow 1 — 5y
0
Actually just ignore the "Touched" error, that's from another script. Abysmallow 1 — 5y
0
First you have to check if you have a local script inside of the startercharacterscripts folder valledestroy 54 — 5y
0
also you can add a wait(10) on the top of the script valledestroy 54 — 5y
View all comments (5 more)
0
That's not what I meant, I need to remove these errors, and if i add wait(10), nothing different happens. Abysmallow 1 — 5y
0
Oh, and I forgot to tell you, you need to run an animation. Sorry! Abysmallow 1 — 5y
0
i told you to use wait becauuse you said that you got an error called Walkspeed is not a valid member of humanoid valledestroy 54 — 5y
0
Also have you even tried how it look when you just change the walkspeed valledestroy 54 — 5y
0
oh my gosh, i am so dumb, i must have made an error in my code, sorry! Abysmallow 1 — 5y
Ad

Answer this question