Blocking And Melee Script [Blocking Wont Work]

** I want to make when the player has a boolvalue named blockAction they take no damage(I already did that). I want it when they don’t have the value in the player for that player to take damage. If the player not blocking the script breaks**

** I want to achieve making the player taking damage while blocking and not blocking. **

	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 Combo == 1 or Combo == 2 or Combo == 3 or Combo == 4 or Combo == 5 then
						local EnemyHum = m:FindFirstChild("Humanoid")
						local blockAction = m:FindFirstChild("Humanoid").blockAction
						if EnemyHum then
							if not blockAction then
								print("Not block action")
								local Damage = Player:WaitForChild("Damage")
								m.Humanoid:TakeDamage(Damage.Value)
								local x = Instance.new("StringValue", m:WaitForChild("Hit player's folder"))
								x.Name = Player.Name
								game.Debris:AddItem(x, 2)
							else
							if blockAction then
									if blockAction.Value > 0 then
										print("Is block Action")
									blockAction.Value = blockAction.Value - 1
									local NBlock = Block:Clone()
									NBlock.CFrame = m:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0,1,0)
									NBlock.Parent = game.Workspace
									game.Debris:AddItem(NBlock,0.5)
									local Particle = NBlock.BodyFrontAttachment.Particle
									Particle:Emit(15)
									if blockAction.Value == 0 then
										print("Block Break")
										spawn(function()
											local enemy = game:GetService("Players"):GetPlayerFromCharacter(m:WaitForChild("Humanoid").Parent)
											if enemy then
												local backpack = enemy:findFirstChild("Backpack")
												if backpack then
													local Melee = backpack:findFirstChild("Melee")
													if Melee then
														local isBroken = Melee.RemoteEvent.Script:findFirstChild("isBroken")
														if isBroken then
															isBroken.Value = true
															print("isbroken")
															wait(3)
														isBroken.Value = false
														end
													end
												end
											end
									end)
										end
									end
								end
							end
						end
					end
1 Like

It could be because your else if statement has a space here

if not blockAction then
    print("Not block action")
    local Damage = Player:WaitForChild("Damage")
    m.Humanoid:TakeDamage(Damage.Value)
    local x = Instance.new("StringValue", m:WaitForChild("Hit player's folder"))
    x.Name = Player.Name
    game.Debris:AddItem(x, 2)
else -- Put elseif here

I had the same problem before and that fixed it

2 Likes

Sorry for the late response but in the script where you inserted an instance of the bool value mainly for blocking purposes, where did you insert it inside? You could’ve inserted it in the parent and not inside the humanoid.

2 Likes

I was able to fix it with the help of roblox wiki but thanks.

Thanks for helping me out. I was able to fix it using the help of Roblox wiki.