I made a HitBox with region3 (I haven't added any type of cooldown/debounce) that was supposed to lower a part's health after a hit. But what happens is that after I active my tool and the 'activate' value in my tool is turned to true, the while/for i, v loop stops work. These are the scripts for both my region3 and my tool.
Region3 script: local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local Region = Region3.new(pos1, pos2)
while true do
print("Started/Restarted Loop!")
wait()
local PartsInRegion = game.Workspace:FindPartsInRegion3(Region, RegionPart, 1000)
for i, RegionPart in pairs(PartsInRegion) do
if RegionPart.Parent:FindFirstChild("Humanoid") ~= nil then
print("Found the Humanoid!")
if RegionPart.Parent:FindFirstChild("Sword") ~= nil then
print("Found the Sword!")
if RegionPart.Parent.Sword:FindFirstChild("Handle") ~= nil then
print("Found the Handle!")
if RegionPart.Parent.Sword.Handle.Active.Value == true then
print("Decreasing RegionPart's Health!")
RegionPart.Humanoid.Health = RegionPart.Humanoid.Health - 30
end
end
end
end
end
end
Tool Script:
local Tool = script.Parent.Parent
local Active = Tool.Handle.Active
Tool.Activated:Connect(function()
Active.Value = true
end)
Tool.Deactivated:Connect(function()
Active.Value = false
end)
Explosion script for my part:
while true do
wait()
if script.Parent.Humanoid.Health == 0 then
local Explosion = Instance.new("Explosion")
Explosion.BlastRadius = 200
Explosion.Position = script.Parent.Position
end
end
