Im making a sort of RPG game with pvp mechanics and parrying is one of them, parry can only happen with a certain sword. for some reason when the player presses R to parry, the animation plays. but when they get hit nothing happens to the attacker and the player just takes damage like normal

local script inside tool to register if player pressed R, this also registers the hits.

local UIS = game:GetService("UserInputService")
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

local Equipped = false
local Cooldown = false

local CurrentlyParrying = false

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()

script.Parent.Equipped:Connect(function()
	Equipped = true
	print(Equipped)
end)

script.Parent.Unequipped:Connect(function()
	Equipped = false
	print(Equipped)
end)

UIS.InputBegan:Connect(function(input)
	if Equipped == true and Cooldown == false then
		if input.KeyCode == Enum.KeyCode.R then
			Cooldown = true
			CurrentlyParrying = true
			game.ReplicatedStorage.Parry:FireServer()

			controls:Disable()

			print("Player press R")
			wait(3)
			CurrentlyParrying = false
			controls:Enable()
			wait(5)

			Cooldown = false
		end
	end
end)

Char:WaitForChild("Humanoid").HealthChanged:Connect(function(health)
	Char.HumanoidRootPart.Touched:Connect(function(part)
		if part.Parent:FindFirstChild("Humanoid") then
			print("Attacker is a player")
			local AttackerHumanoid = part.Parent.Humanoid
			
			game.ReplicatedStorage.ParrySuccess:FireServer()
		end
	end)
end)


ServerScript inside of ServerScript service which registers the events

local ReplicatedStorage = game:GetService("ReplicatedStorage")



ReplicatedStorage.Parry.OnServerEvent:Connect(function(player) --// Parry Event
	
	local CurrentlyParrying = true
	
	local Animation = Instance.new("Animation")
	Animation.AnimationId = "rbxassetid://11889172194"
	
	local Anim = player.Character.Humanoid:LoadAnimation(Animation)
		Anim:Play()
		print("Parry event triggered")
	local char = player.Character
	char.Humanoid:SetAttribute("Mana", char.Humanoid:GetAttribute("Mana") - 25)
	
	wait(3)
	CurrentlyParrying = false
	
end)

ReplicatedStorage.ParrySuccess.OnServerEvent:Connect(function(player, AttackerHumanoid)
	local Attacker = game.Players:GetPlayerFromCharacter(AttackerHumanoid.Parent)
	
	AttackerHumanoid.Health -= 10
	ReplicatedStorage.ParrySuccess:FireClient(Attacker)
	
	
end)

LocalScript inside starterCharacter to freeze the attacker upon hitting the person who parried

local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

game.ReplicatedStorage.ParrySuccess.OnClientEvent:Connect(function()
	controls:Disable()
	wait(2)
	controls:Enable()
end)

3 comments

0

does your console post print("Attacker is a player") properly?

0

A video with the console and a demonstration may help too

0

No, it does not print