Animation Not Being Loaded

So I get an error once the player clicks:

Attempt to index nil with 'LoadAnimation'

Heres the script

-- Rock Animation for R15 and R6. Feel free to use this model, to make your combat system or anything else.

local tool = script.Parent
local character = tool.Parent

local animation15 = script.R15
local animation6 = script.R6

-- Script //

tool.Activated:Connect(function()
	local hum = character:FindFirstChild('Humanoid')
	local ANIM = hum:LoadAnimation(animation15)
	
	ANIM:Play()
	
	wait(.3)
	
	ANIM:Stop()
end)

This could be an issue, when a tool isn’t equipped its saved in the player backpack, and once the tool is equipped then is moved into the character, but since this code is executing at start up the most probably thing to happen is that the tool will be still in the backpack.
I suppose you are in a local script so you can get the player object from game.Players.Localplayer and then get the character from player.Character or player.CharacterAdded:Wait()

I’m using a normal script not a localscript, but I could try the last one.

I had problems with my animations a few days ago > come to find out roblox has made the old way of loading animations “Deprecated” you now have to load the animation in the animator which can be found in the humanoid. Ill list some links.

Deprecating LoadAnimation on Humanoid and AnimationController - Updates / Announcements - DevForum | Roblox

Animator (roblox.com)

Its not too much different than how you’re already loading the animation, so you should be able to fix it easily.

@Ryuunske I did, but the animation isn’t loading.

-- Rock Animation for R15 and R6. Feel free to use this model, to make your combat system or anything else.

local tool = script.Parent or script.Parent.Character
local character = tool.Parent

local animation15 = script.R15
local animation6 = script.R6

-- Script //


local function playAnimationFromServer(character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
			return animationTrack
		end
	end
end


tool.Activated:Connect(function()
    playAnimationFromServer(character, animation15)
end)