Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

InputBegan Error for userinput service?

Ok so I have been getting this error called attempt to index nill with input began Here is code!

Error:

Error: 11:14:42.934 - userInputService.InputBegan:Connect(function(input,gpe) 11:14:42.943 - if input.KeyCode == Enum.KeyCode.LeftControl then 11:14:42.944 - print("Correct input") 11:14:42.945 - crouch() 11:14:42.945 - end 11:14:42.946 - end) 11:14:42.946 - 11:14:42.946 - script.Parent.Crouch.MouseButton1Click:Connect(function() 11:14:42.947 - crouch() 11:14:42.947 - end) 11:14:42.948 - 11:14:42.948 - game.ReplicatedStorage.Togg:1: attempt to index nil with 'InputBegan'

Code.

 userInputService.InputBegan:Connect(function(input,gpe) if input.KeyCode == Enum.KeyCode.LeftControl then print("Correct input") crouch() end end)

script.Parent.Crouch.MouseButton1Click:Connect(function() crouch() end)

game.ReplicatedStorage.ToggleCrouch.OnClientEvent:Connect(function(visiblity) script.Parent.Crouch.Visible = visiblity for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do v:Stop() end player.Character.Humanoid.WalkSpeed = 16 animPlaying = false script.Parent.Crouch.ImageColor3 = Color3.fromRGB(255,255,255) script.Parent.Crouch.TextLabel.BackgroundColor3 = Color3.fromRGB(255,255,255) end)

This is an Alvin Blox tutorial but the thing is I am doing an animation but the animation won't load because of the InputBegan.

1 answer

You are getting this error because you haven't defined userInputService. Adding local userInputService = game:GetService("UserInputService") to the start of the script should fix it.

This discussion is preserved as it was. New answers, comments, and votes are closed.