Hey, I have been playing around, and I want to transform the multiple-target sword to a 3D region, now it is quite buggy.
This is my old post of someone helping me making a sword attacking multiple targets: Attacking multiple targets at once?
local min = blade.Position - (0.5 * blade.Size)
local max = blade.Position + (0.5 * blade.Size)
local region = Region3.new(min,max)
for _,hit in pairs(game.Workspace:FindPartsInRegion3(region,blade)) do
if script.Active.Value == true then
local plr = plrS:FindFirstChild(tool.Parent.Name)
if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Enemy") then
if hit.Name ~= "Blade" then
if hit.Parent.Enemy.Value == true then
local eneH = hit.Parent.Humanoid
local found
for _, character in next, hitE do
if character == eneH then
found = true
end
end
if not found then
print(eneH.Name)
table.insert(hitE, eneH)
if eneH:FindFirstChild("creator") then
if eneH.creator.Value ~= plr then
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = plr
creator_tag.Name = "creator"
creator_tag.Parent = eneH
end
else
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = plr
creator_tag.Name = "creator"
creator_tag.Parent = eneH
end
local dmg = rand:NextNumber(setting.Minimum_Damage,setting.Maximum_Damage)
local absolutedmg = dmg
+ math.abs(reps.Players[plr.Name].skills.strength.Value)*1.66
module.DamageIndicator(absolutedmg,hit.Parent.Head.CFrame * CFrame.new(rand:NextNumber(-.1,.1),2,rand:NextNumber(-.1,.1)))
eneH:TakeDamage(absolutedmg)
end
wait(.3)
for i, character in next, hitE do
if character == eneH then
--script.Active.Value = false
tool.ServerBlade.BrickColor = BrickColor.new("Bright red")
table.remove(hitE, i)
end
end
end
end
end
end
end
I removed a lot of unnecessary code, to try and make it cleaner, now the result is that it deals damage over, and over again. But I know the reason is because of the for loop of the region.
I don’t know how to solve this issue.
That is the problem (yellow numbers are the damage I deal, it deals damage over-time…)
https://gyazo.com/a92084407bba141f6da2f2affbb8a1df