Animation Won't Play

So I pretty much know nothing yet about scripting with animations so here I am. Basically I want the idle animation to be playing while the player is idle and when they left click it will play the card swipe animations.

Here is my code -

local Keycard_Swipe = script.Parent.Animations.KeycardSwipe
local Keycard_Idle = script.Parent.Animations.KeycardIdle
local User_Input_Service = game:GetService("UserInputService")

local CoolDown = false

Keycard_Idle:play()

User_Input_Service.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and CoolDown ~= true then
		Keycard_Swipe:play()
		CoolDown = true
		wait(0.5)
		CoolDown = false
	end
end)

On testing it will give me the error that, “Animations is not a valid member of Tool” which it is as you can see in this image -
image
So if you can help me with this at all it would be appreciated.

1 Like

I think you should’ve load animation to humanoid first, like this:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
--got player, players character, characters humanoid

local Animation = script.Parent.Animations.KeycardIdle --our animation
local AnimTrack = Humanoid:LoadAnimation(Animation) -- load animation
AnimTrack:Play() -- play animation

“Humanoid is not a valid member of model”

Try using Script instead of LocalScript

P.S: You can use remote event for UserInputService.

Wait am I going to have to use events for this?

1 Like

as well make sure your animation’s priority is set to action :slight_smile:

It says I attempted to index nil with Character.