Parry system need help

local fist = script.Parent
local combathit = game:GetService("ReplicatedStorage").Combathit
local handle = fist.Handle
local parrysound = fist.ParrySound
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local hitbox1 = RaycastHitbox.new(fist.Hitbox)
local fistsound = fist.punchsound
local parry = game:GetService("ReplicatedStorage").Parry

config = {
	atktime = 1.3,
	damage = 5,
	parrytime = .7

}


local function onParry(player, blockheldtime)
hitbox1.OnHit:Connect(function(hit, humanoid)
local currenttime = os.time()
		local parryduration = currenttime - blockheldtime
print(parryduration)
		if humanoid.Parent ~= script.Parent.Parent then 
	if parryduration <= config.parrytime then
		print("yes")
			local parryvfx = game.ReplicatedStorage["ParryEffect"].Attachment:Clone()
			parryvfx.Parent = humanoid.Parent:FindFirstChild("HumanoidRootPart")
			parrysound:Play()
			for i,v in pairs(parryvfx:GetChildren()) do
				if v:IsA("ParticleEmitter") then
					v:Emit(v:GetAttribute("EmitCount"))
				end
			end
			game.Debris:AddItem(parryvfx, 1.19)
	elseif parryduration >= config.parrytime then
			humanoid:TakeDamage(config.damage)
			fistsound:Play()
			local hitvfx = game.ReplicatedStorage["Hiteffect"].Attachment:Clone()
			hitvfx.Parent = humanoid.Parent:FindFirstChild("HumanoidRootPart")
			for i,v in pairs(hitvfx:GetChildren()) do
				if v:IsA("ParticleEmitter") then
					v:Emit(v:GetAttribute("EmitCount"))
				end
			end
			local npcred = game.ReplicatedStorage["npchighlight"]:Clone()
			npcred.Parent = humanoid.Parent
			game.Debris:AddItem(npcred,.24)

			game.Debris:AddItem(hitvfx,1)

	end
			print(blockheldtime)
	end
end)
end
parry.OnServerEvent:Connect(onParry)



	

combathit.OnServerEvent:Connect(function()
	hitbox1:HitStart()
	task.wait(config.atktime)
	hitbox1:HitStop()
	end)

parrysystem not working it doesnt damage a dummy unless i the attacker parry without even being hit by anything. Not sure why parry is not working only been scripting for a month bear with me
blockheldtime is the amount of time a player held block for, its passed through client to server.

1 Like

Okay look. I won’t tell you how to fix your system, but I will tell you what you can improve on to make it much better. What you could do is add a attribute to all dummys/players, and when said is hit, check if the attribute is true. If so, do parry things, else don’t.

2 Likes

the parry is not working because os.time() returns the number of seconds as an integer
so the precision is off by a whole second

you should use something like os.clock() to get a precise time, but this value will be different between the client and server

create a numbervalue in replicated storage and change that from the server to os.clock() on an infinite loop

then use that as the measure of time

also you should disconnect the onhit event to prevent memory leak

1 Like