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 4 years ago
Edited 4 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.

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://5044642525"

function onKeyPressed(inputObject, gameProcessEvent)
    if inputObject.KeyCode == Enum.KeyCode then
        humanoid:LoadAnimation(anim):Play()
        humanoid.WalkSpeed = 16*2
    end
end
uis.InputBegan:Connect(onKeyPressed)

1 answer

Log in to vote
0
Answered by 4 years ago

Paste this into a starter charcter script:

local character = game:GetService("Players").LocalPlayer.Character

local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
            character.Humanoid.WalkSpeed = 32
        end
    end
end)

userInputService.InputEnded:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
            character.Humanoid.WalkSpeed = 16
        end
    end
end)
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 — 4y
0
Actually just ignore the "Touched" error, that's from another script. Abysmallow 1 — 4y
0
First you have to check if you have a local script inside of the startercharacterscripts folder valledestroy 54 — 4y
0
also you can add a wait(10) on the top of the script valledestroy 54 — 4y
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 — 4y
0
Oh, and I forgot to tell you, you need to run an animation. Sorry! Abysmallow 1 — 4y
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 — 4y
0
Also have you even tried how it look when you just change the walkspeed valledestroy 54 — 4y
0
oh my gosh, i am so dumb, i must have made an error in my code, sorry! Abysmallow 1 — 4y
Ad

Answer this question