You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
When the user clicks “C” on their keyboard, the player’s character plays the animation
What is the issue? Include screenshots / videos if possible!
I receive the error Players.EncryptedBloxy.PlayerScripts.LocalScript:12: attempt to index nil with 'LoadAnimation'
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
nothing so far
local userInputService = game:GetService("UserInputService")
local crawlAnimation = game.Workspace.Animations.crawl
local char = game.Players.LocalPlayer.Character
if char then
humanoid = char:WaitForChild("Humanoid")
end
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.C then
humanoid:LoadAnimation(crawlAnimation):Play()
end
end)
This is a LocalScript inside StarterPlayerScripts.
Ok so maybe try this I know it’s will change nothing but anyway :
local userInputService = game:GetService("UserInputService")
local crawlAnimation = game.Workspace.Animations.crawl
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.C then
humanoid:WaitForChild("Animator"):LoadAnimation(crawlAnimation):Play()
end
end)
I get an Infinite yield possible on 'Players.EncryptedBloxy.PlayerScripts:WaitForChild("Humanoid") but replacing the WaitForChild for a FindFirstChild makes the original error appear.