Right click block system not working

I’ve tried this with the F key and it has worked, now i just need to make it work with RightClick, I’ve been experimenting with it to make it work but it’s not.
Code:

`wait(2)

local player = game.Players.LocalPlayer
local Character = player.Character or player.Character:Wait() 
local Humanoid = Character:WaitForChild("Humanoid")
local mouse = player:GetMouse()

local block = game:GetService("ReplicatedStorage").Block


local Sword_Block_Animation = Instance.new("Animation")
Sword_Block_Animation.AnimationId = "rbxassetid://9404434731"
local AnimationTrackBlock = Humanoid.Animator:LoadAnimation(Sword_Block_Animation)

mouse.Button2Down:Connect(function(input,inchat)
	if inchat then
	elseif input.Button2Down == mouse.Button2Down then
		local Anim = script.Block
		AnimationTrackBlock:Play()
		block:FireServer()
	end
end)

mouse.Button2Up:Connect(function(input,inchat)
	if inchat then
	elseif input.Button2Up == mouse.Button2Up then
		AnimationTrackBlock:Stop()
		block:FireServer()
	end
end)


Humanoid.block.Changed:Connect(function()
	if Humanoid.block.Value == false then
		AnimationTrackBlock:Stop()
	end
end)
`

Errors:

Workspace.WaterCanxiety.Scimitar.Block:17: attempt to index nil with 'Button2Down'

and

Workspace.WaterCanxiety.Scimitar.Block:26: attempt to index nil with 'Button2Up'
1 Like
game:GetService("UserInputService").InputBegan:Connect(function(input, gpe))
if not gpe then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
--// Script here
end
end

I’m on phone i cant do much

1 Like

Same thing for the “stop block”, just replace it with InputEnded instead