Why doesn't my parrying work?

-- \\ Player-Related Variables //--

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HUM = Character:WaitForChild("Humanoid")

-- \\ Get-Service Variables/Server-Script-Variables // -- 

local UIS = game:GetService("UserInputService")

local RS = game:GetService("ReplicatedStorage")

local SSS = game:GetService("ServerScriptService")


-- \\ Server-Script-Variables // --

local RS = game:GetService("ReplicatedStorage")

local Players = game:GetService("Players")

local KeyProvider = game:GetService("KeyframeSequenceProvider")

-- \\ Cooldowns // --

local Debounce = false


local CDS = {

	1,
	2

}

-- \\ Anims Variables // --

local Animations = script.Parrying

local Anims = Animations.Parrying

local LoadedAnims = Character.Humanoid:LoadAnimation(Anims)


-- \\ Misc. Variables // --

local Blockin = UIS:IsKeyDown(Enum.KeyCode.F)

local CD = 10

local Missed = 15

local curr = 0

local prev = 0

local Held = UIS:IsKeyDown(Enum.KeyCode.F)

local Debounce = false

local ButtonDown = false


-- \\ Functions // --

UIS.InputBegan:Connect(function(Input, Processed)

	if Processed then
		return
	end



	if Input.UserInputType == Enum.UserInputType.MouseButton1 and Character.Humanoid:FindFirstChild("IsBlocking").Value == true then
		print("LOL?")
		if not Processed then
			Debounce = true
			ButtonDown = true
			
			RS.Parrying:FireServer()
			LoadedAnims:Play()
			local curr = os.clock()
			local PT = curr - prev
			if PT < 0.1 then
				
				LoadedAnims:Stop()
				RS.ParryRelease:FireServer()
				Character.Humanoid:FindFirstChild("Parry").Value = false
				Character.Humanoid:FindFirstChild("Blocking").Value = false
				print("BOOM")


				ButtonDown = false
				wait(CD)
				Debounce = false

			end
			
			
		end
	end
end)

UIS.InputEnded:Connect(function(input, typing)
	if typing then return end
	if input.KeyCode == Enum.KeyCode.F and Blockin and ButtonDown == true then

		LoadedAnims:Stop()
		

	end
end)

if Character.Humanoid:FindFirstChild("Parry").Value == false then
	LoadedAnims:Stop()
end

The game is meant to be parrying, and after 0.25 seconds it’ll disable everything, but for some odd reason it won’t stop playing the block animation, and it’ll continuously play the anim.

1 Like

First off, the formatting is atrocious. Secondly, you should kinda make this clear. If I asked a random person what parrying means they would probably give me a weird face.

Also, is this in a local script? Where is it located? These are all questions that should be answered in your post.

I can’t be one to judge though - my posts are trash. I’ll take a look.

Ouch, although thanks for the criticism. I’ll take that in mind the next time I make a local script, since I think a lot more about organization for a module script.

This is indeed a Local Script, and parrying is kind of like blocking if the person had a heavy stun as a downside if they hit the person in that certain timeframe. Sekiro has good examples of that.

Sorry about this rushed post.

I apologize if anything came off as quite rude. I will make sure to keep you posted if I find anything wrong with the script, if not then sorry

1 Like

Where is the “prev” variable being updated? You have a check that determines wether to stop playing the block animation that relies on the difference between curr and prev yet I do not see where prev is updated.

-- \\ Misc. Variables // --

local Blockin = UIS:IsKeyDown(Enum.KeyCode.F)

local CD = 10

local Missed = 15

local curr = 0

local prev = 0

local Held = UIS:IsKeyDown(Enum.KeyCode.F)

local Debounce = false

local ButtonDown = false

If the clock time is not less than .1 how would your animation stop?

The issue was that I couldn’t get the length, or it’d seem very off to do so via a local script to me.

Tbh I don’t quite understand the flow of the parrying process you have. But seems to me that something like this would work:

local parrying = false
local function DoParry(actionName, inputState, inputObj)
	if(actionName == "Parry" and inputState == Enum.UserInputState.Begin)then
		if(Character.Humanoid:FindFirstChild("IsBlocking").Value)then
			if(parrying)then return end --already in progress
			parrying = true --Started
			RS.Parrying:FireServer()
			LoadedAnims:Play() --Don't loop it!
			LoadedAnims.Stopped:Wait()
			RS.ParryRelease:FireServer()
			Character.Humanoid:FindFirstChild("Parry").Value = false
			Character.Humanoid:FindFirstChild("Blocking").Value = false
			task.wait(CD)--Wait cool down period
			parrying = false --finished
		end
	end
end
--This binding could be set once block is activated? Unbind after the parry is complete?
game:GetService("ContextActionService"):BindAction("Parry", DoParry, Enum.UserInputType.MouseButton1)

But then I need it to work during the time they are using both M1, and F.

Could you elaborate on the control flow of the keys. Like if I was a player, explain how I would parry.

Basically, you were a player the kind of flow chart I have in mind is like this:

Player1 is attacking, Player2 is blocking → At a certain timeframe, Player2 is still holding the block key [F] → They would press the Left Mouse button whilst the Block key is still being held → If it misses, the character making the attempt to parry would get punished, their F key being forcibly disabled, disabling blocking → If it does land, the character that was attacking would be dazed and unable to attack giving Player2 a chance to counter the attack.

(If this is confusing or too much just tell me and I will make only the very important part more prominent)

It sounds as if what I provided would accomplish that. When the left mouse button is pressed, the function fires, and checks that the player was blocking. If they were activates the parry. From there you just have to determine if the parry was successful or not.

At this point

	game:GetService("ContextActionService"):BindAction("Parry", DoParry, Enum.UserInputType.MouseButton1)

An error occurs saying
image

game:GetService("ContextActionService"):BindAction("Parry", DoParry, false, Enum.UserInputType.MouseButton1)

Sorry forgot about the make touch button parameter

I have around two last questions.

The blocking animation still seems to be an issue, that lingers. Along with that, how would I achieve the length on my animation?

Whenever you cancel the block then you should be stopping the blocking animation track.

Can you elaborate on this. I’m not sure what you mean.
You can get the length of the track with myTrack.Length

The Blocking Animation track is in a different script which is the issue.

Hrm. Yeah that’s a pickle. In my controllers I keep all the input controls in the same controller module. So I can adjust them based on context like this. Maybe try adding a check to the blocking script that cancels when the blocking value is set to false?

Only one more issue. It seems to disable my combat after doing a parry.