0

I tried making a crouch animation that plays when you press left ctrl on the keyboard. I was expecting it to work, but it doesn't.The animation is for the player. And yes, it is an r15 animation. Any help is appreciated!

So I am trying to make it so when you press left control, a specific animation plays, but it is not working and it keeps getting me an error: "Attempt to index nil with WaitForChild". I tried different things and even if it doesn't give me an error, the script is still not working. It is a LocalScript inside of StarterPlayerScripts and any help would be appreciated. Maybe it's something easy to fix but I am a beginner and I really don't know what to do.

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animation = script.Animation
local animationtrack = animation:LoadAnimation(animation)
uis.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        animation:Play()
    end
end)

2 Answers 2

0

try publishing the animation to the marketplace and using the id, i had a similar issue like this before (you don't have to make the animation on sale)

Sign up to request clarification or add additional context in comments.

Comments

0

The correct way to load animations is using the Humanoid animator, so it would be Humanoid.Animator:LoadAnimation(youranimation)

Example:

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid.Animator

local Animation = script.Animation
local AnimationTrack = Animator:LoadAnimation(Animation)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end -- here we ensure this doesn't trigger if the player is typing in the chat
    if input.KeyCode == Enum.KeyCode.LeftControl then
            AnimationTrack:Play()
    end
end)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.