Need help with a sword script

  1. What do you want to achieve? Keep it simple and clear!
    A lightsaber that can block and attack
  2. What is the issue? Include screenshots / videos if possible!
    I need to make the userinput service work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    It did not work with it.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then		
if script.Parent.Equipped then		
	local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
	local plrhuman = player.Character:FindFirstChild("Humanoid")
	local anim = script.swing1
	local setanim = anim:Clone()
	setanim.Parent = plrhuman
	local animtrack = plrhuman:LoadAnimation(setanim)
	animtrack:Play()
end		
end		
end)
UserInputService.InputBegan:Connect(function(input)
	if script.Parent.Equipped then		
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			print("worked")
		end
	end		
end)	
	

I am not asking for helping with animations and such, just need to know how to make the 2 userinputservice functions work.

Edit: The output has nothing

Is this code in a Server Script or a Local Script? Because if its in a Server Script, UserInputService does not work in Server Scripts. It only functions in Local Scripts.

local UserInputService = game:GetService("UserInputService")

local Tool = script.Parent
local Animation = script:WaitForChild("swing1")

local Equipped

Tool.Equipped:Connect(function()
	Equipped = true
end)

Tool.Unequipped:Connect(function()
	Equipped = false
end)

UserInputService.InputBegan:Connect(function(Input, Processed)
	if Processed then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then		
		if Equipped then
			local Character = Tool.Parent
			local Humanoid = Character.Humanoid
			local Track = Humanoid:LoadAnimation(Animation)
			repeat task.wait() until Track.Length > 0
			Track:Play()
		end		
	end		
end)

UserInputService.InputBegan:Connect(function(Input, Processed)
	if Processed then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton2 then
		if Equipped then
			--Do code.
		end
	end		
end)