My Detection is making the Character the enemy, but it just makes the enemy = character

Basically, I changed my blocking a few days ago. I decided to make it work in the way that if the character was two studs away and he hit the character the damage he would take is halfed by 5. Although, the current issue is that when it loops through the folder, it keeps going for the character that is actually doing the blocking action, and not the other character that is possibly 2 studs away.

local SSS = game:GetService("ServerScriptService")

local Dic = require(SSS:WaitForChild("DictonaryHandler"))

local CTHandler = require(SSS.CombatSent:WaitForChild("CombatHandler"))

local DMG = workspace:WaitForChild("BaseDamage")

local baseDmgVal = DMG.Value

local Players = game:GetService("Players")

local Blocking = Players:GetAttribute("Blocking")

local BlockHandler = {}

function BlockHandler.OffSetDamage(Player, Enemy)
	local Character = Player.Character
	
	for _,Enemy in pairs(workspace.LivingThings:GetChildren()) do
		if not Enemy == Character then
		if (Enemy.HumanoidRootPart.Position-Character.HumanoidRootPart.Position).Magnitude < 2 then
			print(Enemy)
			print(Character)
			if not Dic.find(Character, "Stunned") or Blocking == false then
				CTHandler.CreateHB()
			else
				Enemy.Humanoid:TakeDamage(baseDmgVal/5)
				end
			end
		end
	end	
end




return BlockHandler

So, I changed it from Dot, to another way of magnitude and now it won’t do anything. + Doing the block doing like this, it makes the combat a little buggy on top of it.

1 Like

Cuz you use the same name Enemy for the parameter and in the for loop. So it messes up the calculation aka logic.

So, would I remove the enemy as a para or rename it?

Renaming it is the most ideal solution.

The issue still occurs, printing out

  11:55:35.073  Player1  -  Server - BlockHandler:23

Fixed. It was another issue along side it that needed to get edited just a little.