Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i get the player I'm hitting unable to hit me back?

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
attack = attack + 1
local Character = player.Character
local Humanoid = Character.Humanoid
for i,v in pairs(game.Workspace:GetChildren()) do
	local m = (v:IsA("Model") and v) or nil
    	if m and m:FindFirstChild("Humanoid") and m:FindFirstChild("HumanoidRootPart") and m ~= Character then
			if (Character.HumanoidRootPart.Position - m.HumanoidRootPart.Position).magnitude <= Range then
				
				

if attack == 1 or attack == 3 then
local hitright = m.Humanoid:LoadAnimation(script.Parent.hitright)
hitright:Play()
spawn(function()
m.Humanoid.WalkSpeed = 0
m.Humanoid.JumpPower = 0

1 answer

✓ Accepted answer

From what I gather, you are looking to make the player unable to use attacks whilst being attacked themselves. What you could do, is when the player is hit, add a bool value into the targets character named "Stun".

Next, add a check to the attack script to search for this 'Stun' value.

Basic Example

local tool = script.Parent

tool.Activated:Connect(function()
	local character = tool.Parent

	if character:FindFirstChild("Stunned") then --checks for value. If not,
		return --then stop
	end
	
	local connection

	connection = character:FindFirstChild("RightHand").Touched:Connect(function(hit)
		if hit:IsDescendantOf(character) then return end
	 	if hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
			local stun = Instance.new("BoolValue")
			stun.Name = "Stunned"
			stun.Parent = hit.Parent

			game:GetService("Debris"):AddItem(stun, 0.7) --remove stun
		end
	end)

	wait(.6)
	connection:Disconnect()
end)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.