Parry system not working

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 parrysound = fist.ParrySound
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)
1 Like

why is this only damaging dummys when i get the parrywindow time correct after that then
i can attack them and it deals damage. ive only been scripting for a month so bear with me

1 Like

Could we get more context? Could you provide the code from where you’re firing the “parry” remote event?

1 Like
local char = game:GetService("Players").LocalPlayer.Character
local humanoid = char:FindFirstChild("Humanoid")
local animator = humanoid.Animator
local blockanim = animator:LoadAnimation(script.blockanim)
local blockheldanim = animator:LoadAnimation(script.holdblock)
local fist = script.Parent
local equped = false
local blockheldtime = 0
local fistblockcd = game:GetService("ReplicatedStorage").combatdebounces.blockfistdeb
local parry = game:GetService("ReplicatedStorage").Parry
fistblockcd.Value = false
fistblockcd.Value = false
local fkey = Enum.KeyCode.F
fist.Equipped:Connect(function()
	equped = true
end)
fist.Unequipped:Connect(function()
	equped = false
end)

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if equped == true then
		
		if input.KeyCode == fkey then
			blockheldtime = os.time()
			blockanim:Play()
			humanoid.JumpPower = 0
		 humanoid.WalkSpeed = 8 
		end
		if uis:IsKeyDown(fkey) then
			fistblockcd.Value = true
			blockheldanim:Play()
		end
		
		
	end
end)
uis.InputEnded:Connect(function(input, gpe)
	if gpe then return end
	if equped == true then
	if input.KeyCode == fkey then
			blockheldtime = os.time() - blockheldtime
			parry:FireServer(blockheldtime)
		humanoid.WalkSpeed = 16
			humanoid.JumpPower = 50
		blockanim:Stop()
		blockheldanim:Stop()
		task.wait(.1)
		fistblockcd.Value = false
	end
	end
	end)

this is the block script blockheldtime is how long a player holds f for then it sends that info to server script.

1 Like

Sorry for the super late reply, I’ve been on my alt. I’ve reviewed all your code and can’t seem to see any errors.

Could you go into detail with what the problem it? I’m havin trouble getting what you mean

1 Like

ok ive decided to change and use a attribute instead of sending values through remote events. Now everytime a player holds block for < then .7 it fires to server, how would i referance a humanoid outisde of a hit function or where would i put the onserver event that catches the parryed remote event. in the server script im making a attribute tahts created for each player everytime they jhoin the game, so tahts alr sorted.

2 Likes

Put it inside of the PlayerAdded event I guess

1 Like

Could you provide a video, I don’t really understand your issue.

1 Like
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 playeradded(plr)
	print("bruh")
	plr:SetAttribute("parryed", false)
end
parry.OnServerEvent:Connect(function(plr)		
plr:SetAttribute("parryed", true)
task.wait(.3)
plr:SetAttribute("parryed", false)
end)
hitbox1.OnHit:Connect(function(hit, humanoid)
	print(humanoid.Parent)
	if humanoid.Parent ~= fist.Parent and humanoid.Parent:GetAttribute("parryed") == false 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)
	elseif humanoid.Parent ~= fist.Parent and humanoid.Parent:GetAttribute("parryed") == true then
		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)
		end
		end)


combathit.OnServerEvent:Connect(function()
	hitbox1:HitStart()
	task.wait(config.atktime)
	hitbox1:HitStop()
	end)
	
local players = game.Players
players.PlayerAdded:Connect(playeradded)
for i,plr in pairs(players:GetPlayers()) do
	playeradded(plr)
end

ok ive added atribute to it but now it wont damage other players when testing with 2 players.i have npcs in my game that have parryed atribute on false and i can attack them. I really dont understand what im doing wrong. I even check on each of the players and they both have the atribute created and set to false and true when parryed in time on cilent and server

1 Like

you are using os.time() which returns an integer, so the precision is off by a whole second

use tick() instead

1 Like

ive changed all my anim and block to use os.clock and its much faster now thanks. But now with the same script from above when i get 2 players in a game and try to attack the other, it returns the attribute i made “parryed” as nil. But on both server and client its set to false. With npcs i made that have the atr by default set to false or true it runs without returning nil.

1 Like

os.clock is different on the client and server