Help with this scripting bug

I know what’s happening and what’s making this script not work but I don’t know how to fix it. Here’s the script:

local Player = game.Players.LocalPlayer  
--local Vacuus = Player:WaitForChild("Backpack").Vacuus
--local Mouse = Player:GetMouse()
local Animation = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("VacuusCasting")) 
local ManaStat = Player:WaitForChild("StatsData")["Mana"]
local Cooldown = false 

script.Parent.Activated:Connect(function()
	if Cooldown == true then return end 
	Cooldown = true 
	
	-- THIS CODE WILL PLAY IF THE PLAYER CAST IT RIGHT
	Animation:Play() 
	wait(1.3) 
	Player.Character.Humanoid.WalkSpeed = 4 	
	
	-- LOOPS THE ATTACK 100 TIMES
	for i = 1,100 do
		wait()
		game.ReplicatedStorage["Incantations [EVENTS]"]:WaitForChild("VacuusEvent"):FireServer()
			
	-- IF 'i' IS 100 THEN
		if i == 100 then
			Animation:Stop(0.5)
			Player.Character.Humanoid.WalkSpeed = 16
		end
	end	
	Cooldown = false 
end)

Here’s the error:

I have the script inside the tool:
promblem

Please help !

Maybe put it under script.Parent.Activated:Connect(function()?

local Players = gameGetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("VacuusCasting")) 

The error stopped happening but every time I click with the tool equipped the script function doesn’t work and no errors pop up

Since this is a local script I would do this, I did this in my scripts

local Players = game:GetService("Players")
local player = Players.LocalPlayer

repeat wait(0.25) until player.Character

local Character = player.Character

I know it is inifficient but it works!

Also do this

Humanoid:WaitForChild("Animator"):LoadAnimation()
--instead of
Humanoid:LoadAnimation()
--it is more efficient

Thank you but there’s another error, every time I click with the tool equipped the script function doesn’t work and no errors pop up

Try using

if not Cooldown then
    Cooldown = true
-- THIS CODE WILL PLAY IF THE PLAYER CAST IT RIGHT
	Animation:Play() 
	wait(1.3) 
	Player.Character.Humanoid.WalkSpeed = 4 	
	
	-- LOOPS THE ATTACK 100 TIMES
	for i = 1,100 do
		wait()
		game.ReplicatedStorage["Incantations [EVENTS]"]:WaitForChild("VacuusEvent"):FireServer()
			
	-- IF 'i' IS 100 THEN
		if i == 100 then
			Animation:Stop(0.5)
			Player.Character.Humanoid.WalkSpeed = 16
		end
        Cooldown = false
    
end

Also maybe try for i=1,100,1

You should switch to Animator:LoadAnimation as Humanoid:LoadAnimation is deprecated and could lose support at virtually any time