Faulty sword parry script

This is a parry script I made for a sword, it works by firing an event when the mouse button is pressed down which parries, and when the mouse is up it cancels the parry. There is something wrong with the statements but I cannot see it at all, does anyone see the problem?

LocalScript:
Mouse.Button2Down:Connect(function()
	if Equipped == true then
		Down = true
		print(Down)
		script.Parent.Block:FireServer(Direction, Down)
	end
end)
Mouse.Button2Up:Connect(function()
	if Equipped == true then
		Down = false
		print(Down)
		script.Parent.Block:FireServer(Direction, Down)
	end
end)

ServerScript:
script.Parent.Block.OnServerEvent:Connect(function(Player, Direction, Down)
local LeftBlock = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LeftBlock)
local RightBlock = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.RightBlock)
	if Down == true then
		if Direction == "Left" then
			Block = true
			LeftBlock:Play(nil, nil, 0)
		elseif Direction == "Right" then
			Block = true
			RightBlock:Play(nil, nil, 0)
	elseif Down == false then
		print("work")
		Block = false
		LeftBlock:Stop()
		RightBlock:Stop()
		end
	end
end)
2 Likes

It’s hard to explain where the error is through words, so, I edited the provided code for you. You’re welcome :grin:

ServerScript:

script.Parent.Block.OnServerEvent:Connect(function(Player, Direction, Down)
	local LeftBlock = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LeftBlock)
	local RightBlock = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.RightBlock)
	if Down == true then
		if Direction == "Left" then
			Block = true
			LeftBlock:Play(nil, nil, 0)
		elseif Direction == "Right" then
			Block = true
			RightBlock:Play(nil, nil, 0)
		end
	elseif Down == false then
		print("work")
		Block = false
		LeftBlock:Stop()
		RightBlock:Stop()
	end
end)

If the code works, be sure to mark this as the solution.

3 Likes