Okay so I'm sure you can tell by reading the code but if not I'm trying to play an animation when you press MouseButton1 or a certain key. I'm going to post all of the code I've tried and I would appreciate it some help correcting it. The first one is my most recent attempt which gave me an error of "UserInputService is not a valid member of InputObject" which I'm assuming means I can't use userinputservice for keydown. The only reason I'm using userinputservice is because this YouTube tutorial on how to do this wasn't working so I posted it and they suggested it. So I don't know maybe I'm doing all of this wrong.
--first way--
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local function onInputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
end
local Animation = script:WaitForChild("Animation")
if input.UserInputService == "f" or "F" then
Animation:Play()
end
end
UserInputService.InputBegan:connect(onInputBegan)
--second way--
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
game:GetService('UserInputService')
animation = script:WaitForChild("Animation")
enabled = false
mouse.Button1Down:connect(function()
if enabled ==false
enabled = true
local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
animationTrack:Play()
wait(3)
end
end)
--3rd way--
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
animation = script:WaitForChild("Animation")
enabled = true
local function onInputBegan(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
repeat wait() until player.Character.Humanoid == player.Character.Humanoid:LoadAnimation(animation)
end
end
UserInputService.InputBegan:connect(onInputBegan)
--4th way--
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
animation = script:WaitForChild("Animation")
enabled = true
local function onInputBegan(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
animationTrack:Play()
wait(1)
enabled = true
animationTrack:Play()
end
end
UserInputService.InputBegan:connect(onInputBegan)

3 comments
Also, use Connect instead of connect.
The parent and children stuff should look like this. https://gyazo.com/f5fd0328ce3c0dbd8995adf085575114
Although don't mind the "Q" tool